fix: Fix double backslash before escaped unicode character causing lexing error
@@ -151,10 +151,17 @@ public final class EscapeUtil {
if (cursor + 1 >= input.length()) {
return 0;
}
+
+ // Check for double backslash in prefix "\\\\u" in "\\\\uXXXX"
+ boolean initialEscape = input.charAt(cursor) == '\\' && input.charAt(cursor + 1) == '\\';
+
// Check prefix "\\u" in "\\uXXXX"
+ if (!initialEscape) {
if (input.charAt(cursor) != '\\' || input.charAt(cursor + 1) != 'u') {
return 0;
}
+ }
+
// Compute escape size, initial is 2 for the "\\u"
int len = 2;
// Combined:
@@ -171,10 +178,17 @@ public final class EscapeUtil {
}
// Bounds check, then fetch hex value and store in builder, then return total consumed length
if (cursor + len + 4 <= input.length()) {
+ String substring = input.substring(cursor, cursor + len + 4);
+
+ if (initialEscape) {
+ builder.append(substring);
+ return len + 4;
+ }
+
String unicode = input.substring(cursor + len, cursor + len + 4);
try {
int value = Integer.parseInt(unicode, 16);
- builder.append(value != TERMINATOR ? (char) value : input.substring(cursor, cursor + len + 4));
+ builder.append(value != TERMINATOR ? (char) value : substring);
} catch(NumberFormatException ignored) {
return 0;
}
