Fix pretty JSON when strings end with backslashes
authorKevin Israel <pleasestand@live.com>
Thu, 28 Mar 2013 02:04:58 +0000 (22:04 -0400)
committerKevin Israel <pleasestand@live.com>
Sat, 30 Mar 2013 20:23:24 +0000 (16:23 -0400)
commit217cb2e3a6ea805eee4cc81b1cb43562620f88b3
tree0054058df00d59e82b9c4d9ab5f8c3d997021ee1
parent30ed1302b1ae1a5ba583edd02158a1840dc8dc12
Fix pretty JSON when strings end with backslashes

If a string encoded as part of the output ends in a backslash
(e.g. an edit token), FormatJson::prettyPrint() may incorrectly
treat the unescaped double quote marking the end of the string as
a character that is part of the string.

This is a serious problem in that the "pretty" output may not
necessarily be valid JSON; a later string literal might contain
one or more of these tokens: :[{,]}

To fix the bug, I exploit strtr's behavior when it is given an
associative array having keys of the same length to skip over
escaped backslashes while replacing escaped double quotes with "\x01".

I also updated the corresponding unit test.

Change-Id: I159105b6493c14b82cd0a41a95e04bfed744931e
includes/json/FormatJson.php
tests/phpunit/includes/json/FormatJsonTest.php