[PATCH 2 of 2 STABLE] templater: fix handling of \-escapes in raw string literals

Augie Fackler raf at durin42.com
Mon Jun 22 13:24:07 CDT 2015


On Sun, Jun 21, 2015 at 04:42:56PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1434860683 -32400
> #      Sun Jun 21 13:24:43 2015 +0900
> # Branch stable
> # Node ID 40c1ed4b163e1668c3033125119f0c9d8cbb32d5
> # Parent  2676242b76c64647b68701d927ff7d4288644a61
> templater: fix handling of \-escapes in raw string literals

Queued for stable, thanks.

>
> The backslash character should start escape sequences no matter if a string is
> prefixed with 'r'. They are just not interpreted as escape sequences in raw
> strings. revset.tokenize() handles them correctly, but templater didn't.
>
> https://docs.python.org/2/reference/lexical_analysis.html#string-literals
>
> diff --git a/mercurial/templater.py b/mercurial/templater.py
> --- a/mercurial/templater.py
> +++ b/mercurial/templater.py
> @@ -47,7 +47,7 @@ def tokenizer(data):
>              s = pos
>              while pos < end: # find closing quote
>                  d = program[pos]
> -                if decode and d == '\\': # skip over escaped characters
> +                if d == '\\': # skip over escaped characters
>                      pos += 2
>                      continue
>                  if d == c:
> diff --git a/tests/test-command-template.t b/tests/test-command-template.t
> --- a/tests/test-command-template.t
> +++ b/tests/test-command-template.t
> @@ -2280,6 +2280,17 @@ Test string escaping:
>    <>\n<]>
>    <>\n<
>
> +Test string escaping of quotes:
> +
> +  $ hg log -Ra -r0 -T '{"\""}\n'
> +  "
> +  $ hg log -Ra -r0 -T '{"\\\""}\n'
> +  \"
> +  $ hg log -Ra -r0 -T '{r"\""}\n'
> +  \"
> +  $ hg log -Ra -r0 -T '{r"\\\""}\n'
> +  \\\"
> +
>  Test leading backslashes:
>
>    $ cd latesttag
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list