Unverified Commit 592f7886 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Remove escape dollar parameter in localizations_utils (#54219)

parent 19c8948e
......@@ -387,24 +387,9 @@ class $classNamePrefix$camelCaseName extends $superClass {''';
/// foo\\nbar => 'foo\\\\nbar'
/// foo\\bar => 'foo\\\\bar'
/// foo\ bar => 'foo\\ bar'
/// ```
///
/// When [shouldEscapeDollar] is set to true, the '$' characters in the
/// input will be replaced by '$' in the returned string:
/// ```
/// foo$bar = 'foo\$bar'
/// ```
///
/// When [shouldEscapeDollar] is set to false, '$' will be replaced
/// by '\$' in the returned string:
/// ```
/// foo$bar => 'foo\\\$bar'
/// ```
///
/// [shouldEscapeDollar] is true by default.
String generateString(String value, { bool escapeDollar = true }) {
assert(escapeDollar != null);
String generateString(String value) {
const String backslash = '__BACKSLASH__';
assert(
!value.contains(backslash),
......@@ -412,12 +397,12 @@ String generateString(String value, { bool escapeDollar = true }) {
'"__BACKSLASH__", as it is used as part of '
'backslash character processing.'
);
value = value.replaceAll('\\', backslash);
if (escapeDollar)
value = value.replaceAll('\$', '\\\$');
value = value
// Replace backslashes with a placeholder for now to properly parse
// other special characters.
.replaceAll('\\', backslash)
.replaceAll('\$', '\\\$')
.replaceAll("'", "\\'")
.replaceAll('"', '\\"')
.replaceAll('\n', '\\n')
......@@ -425,6 +410,7 @@ String generateString(String value, { bool escapeDollar = true }) {
.replaceAll('\t', '\\t')
.replaceAll('\r', '\\r')
.replaceAll('\b', '\\b')
// Reintroduce escaped backslashes into generated Dart string.
.replaceAll(backslash, '\\\\');
return "'$value'";
......
......@@ -37,11 +37,7 @@ void main() {
});
test('escapes dollar when escapeDollar is true', () {
expect(generateString(r'ab$c', escapeDollar: true), "'ab\\\$c'");
});
test('does not escape dollar when escapeDollar is false', () {
expect(generateString(r'ab$c', escapeDollar: false), "'ab\$c'");
expect(generateString(r'ab$c'), "'ab\\\$c'");
});
test('handles backslash', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment