@@ -196,14 +196,7 @@ public static StringLiteralSSTNode create(String[] values, int startOffset, int
196
196
throw errors .raiseInvalidSyntax (source , source .createSection (startOffset , endOffset - startOffset ), CANNOT_MIX_MESSAGE );
197
197
}
198
198
if (!isRaw && !isFormat ) {
199
- try {
200
- text = StringUtils .unescapeJavaString (errors , text );
201
- } catch (PException e ) {
202
- e .expect (PythonBuiltinClassType .UnicodeDecodeError , IsBuiltinClassProfile .getUncached ());
203
- String message = e .getMessage ();
204
- message = "(unicode error)" + message .substring (PythonBuiltinClassType .UnicodeDecodeError .getName ().length () + 1 );
205
- throw errors .raiseInvalidSyntax (source , source .createSection (startOffset , endOffset - startOffset ), message );
206
- }
199
+ text = unescapeString (startOffset , endOffset , source , errors , text );
207
200
}
208
201
if (isFormat ) {
209
202
isFormatString = true ;
@@ -224,7 +217,7 @@ public static StringLiteralSSTNode create(String[] values, int startOffset, int
224
217
formatStringLiterals .ensureCapacity (formatStringLiterals .size () + literals .length );
225
218
for (int i = 0 ; i < literals .length ; i ++) {
226
219
if (literals [i ] != null && !isRaw ) {
227
- literals [i ] = StringUtils . unescapeJavaString ( errors , literals [i ]);
220
+ literals [i ] = unescapeString ( startOffset , endOffset , source , errors , literals [i ]);
228
221
}
229
222
formatStringLiterals .add (literals [i ]);
230
223
}
@@ -253,4 +246,15 @@ public static StringLiteralSSTNode create(String[] values, int startOffset, int
253
246
}
254
247
return new RawStringLiteralSSTNode (sb == null ? "" : sb .toString (), startOffset , endOffset );
255
248
}
249
+
250
+ private static String unescapeString (int startOffset , int endOffset , Source source , ParserErrorCallback errors , String text ) {
251
+ try {
252
+ return StringUtils .unescapeJavaString (errors , text );
253
+ } catch (PException e ) {
254
+ e .expect (PythonBuiltinClassType .UnicodeDecodeError , IsBuiltinClassProfile .getUncached ());
255
+ String message = e .getMessage ();
256
+ message = "(unicode error)" + message .substring (PythonBuiltinClassType .UnicodeDecodeError .getName ().length () + 1 );
257
+ throw errors .raiseInvalidSyntax (source , source .createSection (startOffset , endOffset - startOffset ), message );
258
+ }
259
+ }
256
260
}
0 commit comments