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

Unified Diff: native_client_sdk/src/build_tools/easy_template.py

Issue 250773010: [NaCl SDK] easy_template: fix bug when using % in an expression template. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix % after {{}} bug Created 6 years, 8 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
« no previous file with comments | « no previous file | native_client_sdk/src/build_tools/tests/easy_template_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/build_tools/easy_template.py
diff --git a/native_client_sdk/src/build_tools/easy_template.py b/native_client_sdk/src/build_tools/easy_template.py
index d439ea0304e034e39c1866a27bf65e3d3f0796fd..999bdb1f8816e9090aac4c62156da007e312d6d4 100755
--- a/native_client_sdk/src/build_tools/easy_template.py
+++ b/native_client_sdk/src/build_tools/easy_template.py
@@ -32,9 +32,18 @@ def TemplateToPython(template, statement_re, expr_re):
line_ending = line[-1] + line_ending
line = line[:-1]
- m = expr_re.search(line)
- if m:
- line = line.replace('%', '%%')
+ ms = list(expr_re.finditer(line))
+ if ms:
+ # Only replace % with %% outside of the expr matches.
+ new_line = ''
+ start = 0
+ for m in ms:
+ new_line += line[start:m.start()].replace('%', '%%')
+ new_line += line[m.start():m.end()]
+ start = m.end()
+ new_line += line[start:].replace('%', '%%')
+ line = new_line
+
subst_line = r'r"""%s""" %% (%s,)' % (
re.sub(expr_re, '%s', line),
', '.join(re.findall(expr_re, line)))
« no previous file with comments | « no previous file | native_client_sdk/src/build_tools/tests/easy_template_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698