Add hotfix for sticky-notes JSON rendering

Signed-off-by: Ricky Elrod <codeblock@fedoraproject.org>
This commit is contained in:
Rick Elrod 2016-06-21 00:42:13 +00:00
parent 27785b296b
commit 82f1ddf393

View file

@ -228,6 +228,18 @@ $code_data = (empty($mode) ? $geshi->parse_code() : htmlspecialchars($row['data'
$lang->escape($code_data);
$skin->escape($code_data);
// Fix JSON rendering. The JSON spec disallows newlines in string literals
// https://www.ietf.org/rfc/rfc4627.txt :
// "All Unicode characters may be placed within the
// quotation marks except for the characters that must be escaped:
// quotation mark, reverse solidus, and the control characters (U+0000
// through U+001F)."
// ... and since \n is a control character, sticky-notes putting newlines in
// string literals (unescaped) breaks spec.
if ($mode && $mode == 'json') {
$code_data = str_replace("\n", "\\n", $code_data);
}
// Shorten the current URL
$url_shortener = new URLShortener();
$short_url = $url_shortener->shorten($nav->get_paste($row['id'], $hash, $project, true, ''));