Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(embed): escape dollar symbol of JSON string literal #21

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions embed/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.3.1

- fix(embed): escape dollar symbol of JSON string literal (#21 by @Jumpaku)

## 1.3.0

- Update `toml` dependency to 0.15.0 (#17 by @bramp)
Expand Down
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
2 changes: 1 addition & 1 deletion embed/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: embed
description: Code generation for embedding arbitrary file content into Dart code.
version: 1.3.0
version: 1.3.1
repository: https://github.com/fujidaiti/embed.dart.git

environment:
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;
Loading