You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to the nodegit maintainers for this excellent library!
This issue was debugged with the assistance of Cursor and Opus 4.5.
Current Behavior
DiffLine.rawContent() returns a JavaScript string type, but the underlying libgit2 git_diff_line.content is a raw byte pointer (const char *) that is not NUL-terminated and may contain non-UTF-8 encoded content (e.g., GBK, GB18030).
The current implementation in lib/diff_line.js:
var_rawContent=DiffLine.prototype.content;// Save original native methodDiffLine.prototype.content=function(){// ...this._cache.content=Buffer.from(this.rawContent()).slice(0,this.contentLen()).toString("utf8");returnthis._cache.content;};DiffLine.prototype.rawContent=function(){return_rawContent.call(this);// Calls native binding};
The problem is that _rawContent (the native binding) already converts const char * to a JavaScript string, presumably using v8::String::NewFromUtf8() or similar, which assumes UTF-8 encoding.
Expected Behavior
rawContent() should return a Buffer containing the original bytes, allowing users to detect and decode the encoding themselves:
DiffLine.prototype.rawContent=function(){// Return Buffer instead of stringreturn_rawContent.call(this);// Should return Buffer};DiffLine.prototype.content=function(){// ... existing implementationreturnthis.rawContent().slice(0,this.contentLen()).toString("utf8");};
Activity