-
Notifications
You must be signed in to change notification settings - Fork 50
完善空白符判断逻辑,兼容特殊字符(如\u200B)出现的场景 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,7 @@ public static boolean isBlankChar(int c) { | |
| return Character.isWhitespace(c) | ||
| || Character.isSpaceChar(c) | ||
| || c == '\ufeff' | ||
| || c == '\u202a'; | ||
| || Character.getType(c) == Character.FORMAT; | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package io.mybatis.common.util; | ||
|
||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Utils单元测试用例 | ||
| */ | ||
| public class UtilsTest { | ||
|
|
||
| /** | ||
| * 测试常见的空白字符 | ||
| */ | ||
| @Test | ||
| public void testBlankChar() { | ||
| Assert.assertTrue(Utils.isBlankChar(' ')); | ||
| Assert.assertTrue(Utils.isBlankChar('\n')); | ||
| Assert.assertTrue(Utils.isBlankChar('\r')); | ||
| Assert.assertTrue(Utils.isBlankChar('\t')); | ||
| Assert.assertTrue(Utils.isBlankChar('\f')); | ||
|
|
||
| Assert.assertTrue(Utils.isBlankChar('\u00A0')); | ||
| Assert.assertTrue(Utils.isBlankChar('\ufeff')); | ||
| Assert.assertTrue(Utils.isBlankChar('\u3000')); | ||
| Assert.assertTrue(Utils.isBlankChar('\u202a')); | ||
| // 处理来自Word的文本时,偶见此空白字符 | ||
| Assert.assertTrue(Utils.isBlankChar('\u200B')); | ||
|
|
||
| Assert.assertFalse(Utils.isBlankChar('a')); | ||
| Assert.assertFalse(Utils.isBlankChar('z')); | ||
| Assert.assertFalse(Utils.isBlankChar('0')); | ||
| Assert.assertFalse(Utils.isBlankChar('9')); | ||
| Assert.assertFalse(Utils.isBlankChar('/')); | ||
| Assert.assertFalse(Utils.isBlankChar('\\')); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit check for
'\ufeff'on line 95 is now redundant since U+FEFF (Zero Width No-Break Space / BOM) is a FORMAT character and will be matched byCharacter.getType(c) == Character.FORMATon line 96. Consider removing the explicit check on line 95 to avoid duplication.