r84204 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84203‎ | r84204 | r84205 >
Date:22:00, 17 March 2011
Author:janpaul123
Status:deferred
Tags:
Comment:
Removed evalJSON because jQuery already has parseJSON. Also refactored jquery.json.js a bit.
Modified paths:
  • /trunk/extensions/InlineEditor/jquery.json.js (modified) (history)

Diff [purge]

Index: trunk/extensions/InlineEditor/jquery.json.js
@@ -13,7 +13,8 @@
1414 * It is also influenced heavily by MochiKit's serializeJSON, which is
1515 * copyrighted 2005 by Bob Ippolito.
1616 *
17 - * The script has been modified by Jan Paul Posma to always use $.secureEvalJSON.
 17+ * The script has been modified by Jan Paul Posma by removing $.evalJSON, because jQuery
 18+ * already includes $.parseJSON, and moving variables into functions.
1819 */
1920
2021 (function($) {
@@ -110,37 +111,7 @@
111112 return "{" + pairs.join(", ") + "}";
112113 }
113114 };
114 -
115 - /** jQuery.evalJSON(src)
116 - Evaluates a given piece of json source.
117 - **/
118 - $.evalJSON = function(src)
119 - {
120 - return $.secureEvalJSON(src);
121 - //if (typeof(JSON) == 'object' && JSON.parse)
122 - // return JSON.parse(src);
123 - //return eval("(" + src + ")");
124 - };
125115
126 - /** jQuery.secureEvalJSON(src)
127 - Evals JSON in a way that is *more* secure.
128 - **/
129 - $.secureEvalJSON = function(src)
130 - {
131 - if (typeof(JSON) == 'object' && JSON.parse)
132 - return JSON.parse(src);
133 -
134 - var filtered = src;
135 - filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
136 - filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
137 - filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
138 -
139 - if (/^[\],:{}\s]*$/.test(filtered))
140 - return eval("(" + src + ")");
141 - else
142 - throw new SyntaxError("Error parsing JSON, source is not valid.");
143 - };
144 -
145116 /** jQuery.quoteString(string)
146117 Returns a string-repr of a string, escaping quotes intelligently.
147118 Mostly a support function for toJSON.
@@ -154,6 +125,18 @@
155126 **/
156127 $.quoteString = function(string)
157128 {
 129+ var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
 130+
 131+ var _meta = {
 132+ '\b': '\\b',
 133+ '\t': '\\t',
 134+ '\n': '\\n',
 135+ '\f': '\\f',
 136+ '\r': '\\r',
 137+ '"' : '\\"',
 138+ '\\': '\\\\'
 139+ };
 140+
158141 if (string.match(_escapeable))
159142 {
160143 return '"' + string.replace(_escapeable, function (a)
@@ -166,16 +149,4 @@
167150 }
168151 return '"' + string + '"';
169152 };
170 -
171 - var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
172 -
173 - var _meta = {
174 - '\b': '\\b',
175 - '\t': '\\t',
176 - '\n': '\\n',
177 - '\f': '\\f',
178 - '\r': '\\r',
179 - '"' : '\\"',
180 - '\\': '\\\\'
181 - };
182153 })(jQuery);

Status & tagging log