{"action":"created","issue":{"url":"https://api.github.com/repos/nodegit/nodegit/issues/785","labels_url":"https://api.github.com/repos/nodegit/nodegit/issues/785/labels{/name}","comments_url":"https://api.github.com/repos/nodegit/nodegit/issues/785/comments","events_url":"https://api.github.com/repos/nodegit/nodegit/issues/785/events","html_url":"https://github.com/nodegit/nodegit/issues/785","id":116532160,"number":785,"title":"Length of String is wrong.","user":{"login":"watiko","id":199728,"avatar_url":"https://avatars.githubusercontent.com/u/199728?v=3","gravatar_id":"","url":"https://api.github.com/users/watiko","html_url":"https://github.com/watiko","followers_url":"https://api.github.com/users/watiko/followers","following_url":"https://api.github.com/users/watiko/following{/other_user}","gists_url":"https://api.github.com/users/watiko/gists{/gist_id}","starred_url":"https://api.github.com/users/watiko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watiko/subscriptions","organizations_url":"https://api.github.com/users/watiko/orgs","repos_url":"https://api.github.com/users/watiko/repos","events_url":"https://api.github.com/users/watiko/events{/privacy}","received_events_url":"https://api.github.com/users/watiko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-12T11:33:49Z","updated_at":"2015-11-13T15:07:13Z","closed_at":null,"body":"NodeGit uses substring with bytes length comes from strlen but JavaScript requires characters length.\r\nSo non-ascii string will be broken.\r\n\r\nhttps://libgit2.github.com/libgit2/#HEAD/type/git_diff_line\r\ngit_diff_line->content_len : Number of bytes of data\r\n\r\nNodeGit:\r\nhttps://github.com/nodegit/nodegit/blob/v0.5.0/lib/convenient_line.js#L71\r\n\r\nSome other implementations:\r\nhttps://github.com/libgit2/rugged/blob/v0.23.3/ext/rugged/rugged_diff_line.c#L68\r\nhttps://github.com/libgit2/libgit2sharp/blob/v0.21.1/LibGit2Sharp/Core/EncodingMarshaler.cs#L129\r\nhttps://github.com/libgit2/objective-git/blob/0.8.8/ObjectiveGit/GTDiffLine.m#L22\r\n\r\nThx."},"comment":{"url":"https://api.github.com/repos/nodegit/nodegit/issues/comments/156456371","html_url":"https://github.com/nodegit/nodegit/issues/785#issuecomment-156456371","issue_url":"https://api.github.com/repos/nodegit/nodegit/issues/785","id":156456371,"user":{"login":"watiko","id":199728,"avatar_url":"https://avatars.githubusercontent.com/u/199728?v=3","gravatar_id":"","url":"https://api.github.com/users/watiko","html_url":"https://github.com/watiko","followers_url":"https://api.github.com/users/watiko/followers","following_url":"https://api.github.com/users/watiko/following{/other_user}","gists_url":"https://api.github.com/users/watiko/gists{/gist_id}","starred_url":"https://api.github.com/users/watiko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watiko/subscriptions","organizations_url":"https://api.github.com/users/watiko/orgs","repos_url":"https://api.github.com/users/watiko/repos","events_url":"https://api.github.com/users/watiko/events{/privacy}","received_events_url":"https://api.github.com/users/watiko/received_events","type":"User","site_admin":false},"created_at":"2015-11-13T15:07:13Z","updated_at":"2015-11-13T15:07:13Z","body":"I wrote a following ugly fix in the layer of JavaScript.\r\nBut I think this issue should be resolved in that of C++.\r\n\r\n```diff\r\n--- a/convenient_line.js\t2015-11-13 23:47:56.299338415 +0900\r\n+++ b/convenient_line.js\t2015-11-13 23:48:19.766911535 +0900\r\n@@ -67,8 +67,22 @@\r\n * @return {String}\r\n */\r\n ConvenientLine.prototype.content = function() {\r\n-  return this.raw.content()\r\n-    .substring(0, this.raw.contentLen()).replace(\"\\n\", \"\");\r\n+  function countBytes(chr) {\r\n+      return (encodeURIComponent(chr).replace(/%../g,\"x\").length);\r\n+  }\r\n+\r\n+  var rawContent = this.raw.content();\r\n+  var rawContentLen = this.raw.contentLen();\r\n+  var trueContentLen = 0;\r\n+\r\n+  rawContent.split('').some(function(chr) {\r\n+    rawContentLen -= countBytes(chr);\r\n+    trueContentLen += 1;\r\n+    if (rawContentLen == 0)\r\n+      return true;\r\n+  });\r\n+\r\n+  return rawContent.substring(0, trueContentLen).replace(\"\\n\", \"\");\r\n };\r\n \r\n NodeGit.ConvenientLine = ConvenientLine;\r\n```"}}