[PATCH] templatefilters: don't escape <> in JSON

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jan 16 02:48:15 CST 2015



On 01/15/2015 09:04 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1421384385 28800
> #      Thu Jan 15 20:59:45 2015 -0800
> # Node ID a07b22eefd8e4c629b739778b3ca5f3d53a8b1de
> # Parent  049a9e3a078d7c988cb12ed456aad6ec2779ea69
> templatefilters: don't escape <> in JSON
>
> 55c763926a28 added escaping of "<" and ">" in JSON. I could not find any
> specification claiming that these are special characters that need to be
> escaped. Furthermore, feeding these characters through both Python's and
> SpiderMonkey's JSON serialization API revealed no escaping.

CCing matt as he is the paranoid who did this. Tests or more extensible 
explanation would be cool.

>
> diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py
> +++ b/mercurial/templatefilters.py
> @@ -221,9 +221,9 @@ def _uescape(c):
>
>   _escapes = [
>       ('\\', '\\\\'), ('"', '\\"'), ('\t', '\\t'), ('\n', '\\n'),
>       ('\r', '\\r'), ('\f', '\\f'), ('\b', '\\b'),
> -    ('<', '\\u003c'), ('>', '\\u003e'), ('\0', '\\u0000')
> +    ('\0', '\\u0000'),
>   ]
>
>   def jsonescape(s):
>       for k, v in _escapes:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list