Skip to content

Commit 38a7b2a

Browse files
committed
fix: Fix double backslash before escaped unicode character causing lexing error
1 parent bc8c92a commit 38a7b2a

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/java/me/coley/recaf/util/EscapeUtil.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,17 @@ private static int computeEscapeUnicode(String input, int cursor, StringBuilder
151151
if (cursor + 1 >= input.length()) {
152152
return 0;
153153
}
154+
155+
// Check for double backslash in prefix "\\\\u" in "\\\\uXXXX"
156+
boolean initialEscape = input.charAt(cursor) == '\\' && input.charAt(cursor + 1) == '\\';
157+
154158
// Check prefix "\\u" in "\\uXXXX"
155-
if (input.charAt(cursor) != '\\' || input.charAt(cursor + 1) != 'u') {
156-
return 0;
159+
if (!initialEscape) {
160+
if (input.charAt(cursor) != '\\' || input.charAt(cursor + 1) != 'u') {
161+
return 0;
162+
}
157163
}
164+
158165
// Compute escape size, initial is 2 for the "\\u"
159166
int len = 2;
160167
// Combined:
@@ -171,10 +178,17 @@ private static int computeEscapeUnicode(String input, int cursor, StringBuilder
171178
}
172179
// Bounds check, then fetch hex value and store in builder, then return total consumed length
173180
if (cursor + len + 4 <= input.length()) {
181+
String substring = input.substring(cursor, cursor + len + 4);
182+
183+
if (initialEscape) {
184+
builder.append(substring);
185+
return len + 4;
186+
}
187+
174188
String unicode = input.substring(cursor + len, cursor + len + 4);
175189
try {
176190
int value = Integer.parseInt(unicode, 16);
177-
builder.append(value != TERMINATOR ? (char) value : input.substring(cursor, cursor + len + 4));
191+
builder.append(value != TERMINATOR ? (char) value : substring);
178192
} catch(NumberFormatException ignored) {
179193
return 0;
180194
}

0 commit comments

Comments
 (0)