Fix binary detection for text files containing emoji #79
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
isBinaryFileSync
function incorrectly identifies UTF-8 text files with emoji as binary.Cause
Emoji characters are represented using multiple bytes in UTF-8, each greater than
0x80
. The function counts these as suspicious, leading to misclassification.Fix
The UTF-8 detection logic has been updated:
0xc0
to0xdf
) are valid if the next byte is0x80
to0xbf
.0xe0
to0xef
) are valid if the next 2 bytes are0x80
to0xbf
.0xf0
to0xf7
) are valid if the next 3 bytes are0x80
to0xbf
.Valid UTF-8 characters are no longer counted as suspicious.
Result
Text files with emoji are now correctly identified as text, not binary.
Let me know if you have any further questions!