提交 0cc472a5 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not quote other lower case characters, they don't have upper case mappings

上级 6545e9c9
...@@ -212,6 +212,16 @@ public class ParserUtil { ...@@ -212,6 +212,16 @@ public class ParserUtil {
*/ */
public static final int WITH = WHERE + 1; public static final int WITH = WHERE + 1;
private static final int UPPER_OR_OTHER_LETTER =
1 << Character.UPPERCASE_LETTER
| 1 << Character.TITLECASE_LETTER
| 1 << Character.MODIFIER_LETTER
| 1 << Character.OTHER_LETTER;
private static final int UPPER_OR_OTHER_LETTER_OR_DIGIT =
UPPER_OR_OTHER_LETTER
| 1 << Character.DECIMAL_DIGIT_NUMBER;
private ParserUtil() { private ParserUtil() {
// utility class // utility class
} }
...@@ -242,13 +252,12 @@ public class ParserUtil { ...@@ -242,13 +252,12 @@ public class ParserUtil {
} }
char c = s.charAt(0); char c = s.charAt(0);
// lowercase a-z is quoted as well // lowercase a-z is quoted as well
if ((!Character.isLetter(c) && c != '_') || Character.isLowerCase(c)) { if ((UPPER_OR_OTHER_LETTER >>> Character.getType(c) & 1) == 0 && c != '_') {
return false; return false;
} }
for (int i = 1, length = s.length(); i < length; i++) { for (int i = 1, length = s.length(); i < length; i++) {
c = s.charAt(i); c = s.charAt(i);
if ((!Character.isLetterOrDigit(c) && c != '_') || if ((UPPER_OR_OTHER_LETTER_OR_DIGIT >>> Character.getType(c) & 1) == 0 && c != '_') {
Character.isLowerCase(c)) {
return false; return false;
} }
} }
......
...@@ -336,12 +336,16 @@ public class TestStatement extends TestDb { ...@@ -336,12 +336,16 @@ public class TestStatement extends TestDb {
assertEquals("\"FROM\"", statBC.enquoteIdentifier("FROM", false)); assertEquals("\"FROM\"", statBC.enquoteIdentifier("FROM", false));
assertEquals("\"Test\"", statBC.enquoteIdentifier("Test", false)); assertEquals("\"Test\"", statBC.enquoteIdentifier("Test", false));
assertEquals("\"TODAY\"", statBC.enquoteIdentifier("TODAY", false)); assertEquals("\"TODAY\"", statBC.enquoteIdentifier("TODAY", false));
// Other lower case characters don't have upper case mappings
assertEquals("\u00AA", statBC.enquoteIdentifier("\u00AA", false));
assertTrue(statBC.isSimpleIdentifier("SOME_ID")); assertTrue(statBC.isSimpleIdentifier("SOME_ID"));
assertFalse(statBC.isSimpleIdentifier("SOME ID")); assertFalse(statBC.isSimpleIdentifier("SOME ID"));
assertFalse(statBC.isSimpleIdentifier("FROM")); assertFalse(statBC.isSimpleIdentifier("FROM"));
assertFalse(statBC.isSimpleIdentifier("Test")); assertFalse(statBC.isSimpleIdentifier("Test"));
assertFalse(statBC.isSimpleIdentifier("TODAY")); assertFalse(statBC.isSimpleIdentifier("TODAY"));
// Other lower case characters don't have upper case mappings
assertTrue(statBC.isSimpleIdentifier("\u00AA"));
stat.close(); stat.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论