File tree 2 files changed +8
-2
lines changed
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ class Interpolate implements Function {
49
49
if (index < startIdx) {
50
50
// Empty strings could be stripped thanks to the stringify
51
51
// formatter
52
- expParts.add ('"${template .substring (index , startIdx )}"' );
52
+ expParts.add ('"${_escapeQuotes ( template .substring (index , startIdx ) )}"' );
53
53
}
54
54
expParts.add ('(' + template.substring (startIdx + startLen, endIdx) +
55
55
'|stringify)' );
@@ -58,11 +58,13 @@ class Interpolate implements Function {
58
58
hasInterpolation = true ;
59
59
} else {
60
60
// we did not find any interpolation, so add the remainder
61
- expParts.add ('"${template .substring (index )}"' );
61
+ expParts.add ('"${_escapeQuotes ( template .substring (index ) )}"' );
62
62
break ;
63
63
}
64
64
}
65
65
66
66
return ! mustHaveExpression || hasInterpolation ? expParts.join ('+' ) : null ;
67
67
}
68
+
69
+ _escapeQuotes (s) => s.replaceAll (r'\' , r'\\' ).replaceAll (r'"' , r'\"' );
68
70
}
Original file line number Diff line number Diff line change @@ -33,5 +33,9 @@ main() {
33
33
.toEqual ('"X\n Y"+(A\n +B|stringify)+"C\n D"' );
34
34
});
35
35
36
+ it ('should escape double quotes' , (Interpolate interpolate) {
37
+ expect (interpolate (r'"{{a}}' )).toEqual (r'"\""+(a|stringify)' );
38
+ expect (interpolate (r'\"{{a}}' )).toEqual (r'"\\\""+(a|stringify)' );
39
+ });
36
40
});
37
41
}
You can’t perform that action at this time.
0 commit comments