DiffLine.rawContent() returns string instead of Buffer, causing non-UTF-8 encoding corruption
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- git, javascript, node.js
Direzione di ricerca
Inspect lib/diff_line.js and the native binding behind DiffLine.rawContent(); first trace how content bytes cross the binding boundary and how contentLen() is used. Reproduce the behavior with non-UTF-8 input such as GBK or GB18030, then verify that rawContent() preserves the original bytes and content() still returns UTF-8 text.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
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 method
DiffLine.prototype.content = function() {
// ...
this._cache.content = Buffer.from(this.rawContent())
.slice(0, this.contentLen())
.toString("utf8");
return this._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 string
return _rawContent.call(this); // Should return Buffer
};
DiffLine.prototype.content = function() {
// ... existing implementation
return this.rawContent()
.slice(0, this.contentLen())
.toString("utf8");
};
- Lingua principale
- JavaScript
- Stelle
- 5.8k
- Fork
- 704
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodegit/nodegit
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
Tutte le issue di nodegit/nodegit
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Seeed-Studio/wiki-documents#5655 · 2 commenti ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
capricorn86/happy-dom#2435 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Edit: CW+ Apertachannels:edit check:passed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
01 type: bug 30 needs: triage 99 tag: UX Accessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100