Skip to content

Commit

Permalink
fix(embed): escape dollar symbol of JSON string literal
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumpaku committed Jun 14, 2024
1 parent 894ada9 commit 648ff8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion embed/lib/src/literal/dart_literals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StringLiteral extends DartLiteral<String> {

@override
String toString() {
final literal = value.replaceAll('"', r'\"');
final literal = value.replaceAll('"', r'\"').replaceAll(r'$', r'\$');
return '"$literal"';
}
}
Expand Down
11 changes: 11 additions & 0 deletions embed/test/literal/literal_embedding_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,14 @@ const _$mapPattern = {"a": 0, "b": 0.0, "c": true};
""",
)
Map<String, dynamic>? mapPattern;

@TestEmbedLiteral(
extension: "json",
content: r"""
{ "dollar": "$" }
""",
shouldGenerate: r"""
const _$stringLiteralsDollar = (dollar: "\$");
""",
)
var stringLiteralsDollar;

0 comments on commit 648ff8e

Please sign in to comment.