Commit 5528a657 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Template Expressions: Use a double escape for commas in i18nPolymer

The single escape does not work correctly for the case of replacements
within an HTML template string in JS, and the double escape works
correctly both for the template string in JS case and the normal HTML
replacement case.

Discovered while migrating the extensions page to use Polymer 3,
specifically the i18nPolymer replacements in shortcut_input.html,
which contain commas for Chrome OS.

Bug: 1004967
Change-Id: Ifb7a743cc2048942294a1cb93f73871191ffa254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826279Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700428}
parent 5701d705
...@@ -78,7 +78,7 @@ std::string PolymerParameterEscape(const std::string& in_string) { ...@@ -78,7 +78,7 @@ std::string PolymerParameterEscape(const std::string& in_string) {
out.append("&quot;"); out.append("&quot;");
break; break;
case ',': case ',':
out.append("\\,"); out.append("\\\\,");
break; break;
default: default:
out += c; out += c;
......
...@@ -78,12 +78,12 @@ TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPolymerMixed) { ...@@ -78,12 +78,12 @@ TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPolymerMixed) {
static TemplateReplacements substitutions; static TemplateReplacements substitutions;
substitutions["punctuationSample"] = "a\"b'c<d>e&f,g"; substitutions["punctuationSample"] = "a\"b'c<d>e&f,g";
substitutions["htmlSample"] = "<div>hello</div>"; substitutions["htmlSample"] = "<div>hello</div>";
EXPECT_EQ("a&quot;b\\'c<d>e&f\\,g", EXPECT_EQ("a&quot;b\\'c<d>e&f\\\\,g",
ReplaceTemplateExpressions("$i18nPolymer{punctuationSample}", ReplaceTemplateExpressions("$i18nPolymer{punctuationSample}",
substitutions)); substitutions));
EXPECT_EQ("<div>hello</div>", ReplaceTemplateExpressions( EXPECT_EQ("<div>hello</div>", ReplaceTemplateExpressions(
"$i18nPolymer{htmlSample}", substitutions)); "$i18nPolymer{htmlSample}", substitutions));
EXPECT_EQ("multiple: <div>hello</div>, a&quot;b\\'c<d>e&f\\,g.", EXPECT_EQ("multiple: <div>hello</div>, a&quot;b\\'c<d>e&f\\\\,g.",
ReplaceTemplateExpressions("multiple: $i18nPolymer{htmlSample}, " ReplaceTemplateExpressions("multiple: $i18nPolymer{htmlSample}, "
"$i18nPolymer{punctuationSample}.", "$i18nPolymer{punctuationSample}.",
substitutions)); substitutions));
......
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