Show More
@@ -59,6 +59,41 b' def tokenizer(data):' | |||||
59 | pos += 1 |
|
59 | pos += 1 | |
60 | else: |
|
60 | else: | |
61 | raise error.ParseError(_("unterminated string"), s) |
|
61 | raise error.ParseError(_("unterminated string"), s) | |
|
62 | elif (c == '\\' and program[pos:pos + 2] in (r"\'", r'\"') | |||
|
63 | or c == 'r' and program[pos:pos + 3] in (r"r\'", r'r\"')): | |||
|
64 | # handle escaped quoted strings for compatibility with 2.9.2-3.4, | |||
|
65 | # where some of nested templates were preprocessed as strings and | |||
|
66 | # then compiled. therefore, \"...\" was allowed. (issue4733) | |||
|
67 | # | |||
|
68 | # processing flow of _evalifliteral() at 5ab28a2e9962: | |||
|
69 | # outer template string -> stringify() -> compiletemplate() | |||
|
70 | # ------------------------ ------------ ------------------ | |||
|
71 | # {f("\\\\ {g(\"\\\"\")}"} \\ {g("\"")} [r'\\', {g("\"")}] | |||
|
72 | # ~~~~~~~~ | |||
|
73 | # escaped quoted string | |||
|
74 | if c == 'r': | |||
|
75 | pos += 1 | |||
|
76 | token = 'rawstring' | |||
|
77 | else: | |||
|
78 | token = 'string' | |||
|
79 | quote = program[pos:pos + 2] | |||
|
80 | s = pos = pos + 2 | |||
|
81 | while pos < end: # find closing escaped quote | |||
|
82 | if program.startswith('\\\\\\', pos, end): | |||
|
83 | pos += 4 # skip over double escaped characters | |||
|
84 | continue | |||
|
85 | if program.startswith(quote, pos, end): | |||
|
86 | try: | |||
|
87 | # interpret as if it were a part of an outer string | |||
|
88 | data = program[s:pos].decode('string-escape') | |||
|
89 | except ValueError: # unbalanced escapes | |||
|
90 | raise error.ParseError(_("syntax error"), s) | |||
|
91 | yield (token, data, s) | |||
|
92 | pos += 1 | |||
|
93 | break | |||
|
94 | pos += 1 | |||
|
95 | else: | |||
|
96 | raise error.ParseError(_("unterminated string"), s) | |||
62 | elif c.isalnum() or c in '_': |
|
97 | elif c.isalnum() or c in '_': | |
63 | s = pos |
|
98 | s = pos | |
64 | pos += 1 |
|
99 | pos += 1 |
@@ -2291,6 +2291,50 b' Test string escaping of quotes:' | |||||
2291 | $ hg log -Ra -r0 -T '{r"\\\""}\n' |
|
2291 | $ hg log -Ra -r0 -T '{r"\\\""}\n' | |
2292 | \\\" |
|
2292 | \\\" | |
2293 |
|
2293 | |||
|
2294 | Test compatibility with 2.9.2-3.4 of escaped quoted strings in nested | |||
|
2295 | _evalifliteral() templates (issue4733): | |||
|
2296 | ||||
|
2297 | $ cd latesttag | |||
|
2298 | ||||
|
2299 | $ hg log -r 2 -T '{if(rev, "\"{rev}")}\n' | |||
|
2300 | "2 | |||
|
2301 | $ hg log -r 2 -T '{if(rev, "{if(rev, \"\\\"{rev}\")}")}\n' | |||
|
2302 | "2 | |||
|
2303 | $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, \\\"\\\\\\\"{rev}\\\")}\")}")}\n' | |||
|
2304 | "2 | |||
|
2305 | ||||
|
2306 | $ hg log -r 2 -T '{if(rev, "\\\"")}\n' | |||
|
2307 | \" | |||
|
2308 | $ hg log -r 2 -T '{if(rev, "{if(rev, \"\\\\\\\"\")}")}\n' | |||
|
2309 | \" | |||
|
2310 | $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, \\\"\\\\\\\\\\\\\\\"\\\")}\")}")}\n' | |||
|
2311 | \" | |||
|
2312 | ||||
|
2313 | $ hg log -r 2 -T '{if(rev, r"\\\"")}\n' | |||
|
2314 | \\\" | |||
|
2315 | $ hg log -r 2 -T '{if(rev, "{if(rev, r\"\\\\\\\"\")}")}\n' | |||
|
2316 | \\\" | |||
|
2317 | $ hg log -r 2 -T '{if(rev, "{if(rev, \"{if(rev, r\\\"\\\\\\\\\\\\\\\"\\\")}\")}")}\n' | |||
|
2318 | \\\" | |||
|
2319 | ||||
|
2320 | escaped single quotes and errors: | |||
|
2321 | ||||
|
2322 | $ hg log -r 2 -T "{if(rev, '{if(rev, \'foo\')}')}"'\n' | |||
|
2323 | foo | |||
|
2324 | $ hg log -r 2 -T "{if(rev, '{if(rev, r\'foo\')}')}"'\n' | |||
|
2325 | foo | |||
|
2326 | $ hg log -r 2 -T '{if(rev, "{if(rev, \")}")}\n' | |||
|
2327 | hg: parse error at 11: unterminated string | |||
|
2328 | [255] | |||
|
2329 | $ hg log -r 2 -T '{if(rev, \"\\"")}\n' | |||
|
2330 | hg: parse error at 11: syntax error | |||
|
2331 | [255] | |||
|
2332 | $ hg log -r 2 -T '{if(rev, r\"\\"")}\n' | |||
|
2333 | hg: parse error at 12: syntax error | |||
|
2334 | [255] | |||
|
2335 | ||||
|
2336 | $ cd .. | |||
|
2337 | ||||
2294 | Test leading backslashes: |
|
2338 | Test leading backslashes: | |
2295 |
|
2339 | |||
2296 | $ cd latesttag |
|
2340 | $ cd latesttag |
General Comments 0
You need to be logged in to leave comments.
Login now