Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Unified Diff: ui/base/template_expressions.cc

Issue 2681623002: [i18n] $i18nPolymer to backslash escape (Closed)
Patch Set: moo Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/template_expressions.cc
diff --git a/ui/base/template_expressions.cc b/ui/base/template_expressions.cc
index b8867d8cfaa1bdf2f3d5d42935063284235164d9..c8d49a95f86e55bc3e31e79974367116f413dee6 100644
--- a/ui/base/template_expressions.cc
+++ b/ui/base/template_expressions.cc
@@ -15,6 +15,29 @@ const char kLeader[] = "$i18n";
const size_t kLeaderSize = arraysize(kLeader) - 1;
const char kKeyOpen = '{';
const char kKeyClose = '}';
+
+// Escape quotes and backslashes ('"\) with backslashes.
+std::string BackslashEscape(const std::string& in_string) {
+ std::string out;
+ out.reserve(in_string.size() * 2);
+ for (const char c : in_string) {
+ switch (c) {
+ case '\\':
+ out.append("\\\\");
+ break;
+ case '\'':
+ out.append("\\'");
+ break;
+ case '"':
+ out.append("\\\"");
+ break;
+ default:
+ out += c;
+ }
+ }
+ return out;
+}
+
} // namespace
namespace ui {
@@ -77,6 +100,9 @@ std::string ReplaceTemplateExpressions(
replacement = net::EscapeForHTML(replacement);
} else if (context == "Raw") {
// Pass the replacement through unchanged.
+ } else if (context == "Polymer") {
+ // Escape quotes and backslash for '$i18nPolymer{}' use (i.e. quoted).
+ replacement = BackslashEscape(replacement);
} else {
CHECK(false) << "Unknown context " << context;
}
« no previous file with comments | « chrome/browser/resources/settings/site_settings_page/site_settings_page.html ('k') | ui/base/template_expressions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698