@@ -257,8 +257,10 @@ private String builtInArguments(TypeElement builtIn, boolean omitSelfParam) {
257
257
}
258
258
});
259
259
260
- names .add ("\" " + nameSB + "\" " );
261
- defaultVals .add (defaultVal != null ? "\" " + defaultVal + "\" " : "null" );
260
+ names .add ("\" " + escapeString (nameSB .toString ()) + "\" " );
261
+ defaultVals .add (
262
+ (defaultVal != null ? "\" " + escapeString (defaultVal ) + "\" " : "null" )
263
+ );
262
264
}
263
265
264
266
return (
@@ -342,9 +344,9 @@ private void processBuiltInFactory(TypeElement builtInFactoryClass) throws IOExc
342
344
343
345
return (
344
346
" new BuiltInFunctionValue(\" " +
345
- fnAnnot .name () +
347
+ escapeString ( fnAnnot .name () ) +
346
348
"\" , \" " +
347
- fnAnnot .doc () +
349
+ escapeString ( fnAnnot .doc () ) +
348
350
"\" , " +
349
351
builtInArguments (builtInFn , false ) +
350
352
", BuiltInBody.create(" +
@@ -416,9 +418,9 @@ private void processBuiltInFactory(TypeElement builtInFactoryClass) throws IOExc
416
418
"BuiltInMethodFactory." +
417
419
(isProperty ? "createAttribute" : "createMethod" ) +
418
420
"(\" " +
419
- name +
421
+ escapeString ( name ) +
420
422
"\" , \" " +
421
- doc +
423
+ escapeString ( doc ) +
422
424
"\" " +
423
425
(isProperty ? "" : ", " + builtInArguments (builtInMethod , true )) +
424
426
", BuiltInBody.create(" +
@@ -431,7 +433,7 @@ private void processBuiltInFactory(TypeElement builtInFactoryClass) throws IOExc
431
433
return (
432
434
" Pair.create(new String[] {" +
433
435
Arrays .stream (targetTypes )
434
- .map (t -> "\" " + t + "\" " )
436
+ .map (t -> "\" " + escapeString ( t ) + "\" " )
435
437
.collect (Collectors .joining (", " )) +
436
438
" }," +
437
439
wrapper +
@@ -448,4 +450,15 @@ private void processBuiltInFactory(TypeElement builtInFactoryClass) throws IOExc
448
450
449
451
builtInPackages .add (Pair .create (packageName , className ));
450
452
}
453
+
454
+ /** Return the `input` string with all special characters escaped. */
455
+ private static String escapeString (String input ) {
456
+ return input
457
+ .replace ("\n " , "\\ n" )
458
+ .replace ("\r " , "\\ r" )
459
+ .replace ("\t " , "\\ t" )
460
+ .replace ("\b " , "\\ b" )
461
+ .replace ("\f " , "\\ f" )
462
+ .replace ("\" " , "\\ \" " );
463
+ }
451
464
}
0 commit comments