fix: handle multi-byte UTF-8 characters in DeleteWhiteSpace#34
Open
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Open
fix: handle multi-byte UTF-8 characters in DeleteWhiteSpace#34Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Conversation
DeleteWhiteSpace iterated over string bytes (str[i]) and cast each
byte to rune, which corrupts multi-byte UTF-8 characters like
Chinese, Japanese, Korean, emoji, etc.
DeleteWhiteSpace(" 测试 测试 ") → "æµ\x8dè¯\x95æµ\x8dè¯\x95"
Fix: use range-based iteration which correctly yields Unicode runes.
DeleteWhiteSpace(" 测试 测试 ") → "测试测试"
Fixes Masterminds#29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #29
Problem
DeleteWhiteSpaceiterates by byte index (str[i]) and casts each byte torune. For multi-byte UTF-8 characters (Chinese, Japanese, Korean, emoji, etc.), this produces mojibake:Fix
Use
range-based iteration which correctly yields Unicode runes instead of raw bytes.All existing tests pass.