mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-23 06:21:12 +02:00
Added escaping for json strings
This commit is contained in:
@@ -11,12 +11,61 @@
|
|||||||
|
|
||||||
/* The egw_json_request is the javaScript side implementation of class.egw_json.inc.php.*/
|
/* The egw_json_request is the javaScript side implementation of class.egw_json.inc.php.*/
|
||||||
|
|
||||||
function egw_json_encode_simple(input)
|
function _egw_json_escape_string(input)
|
||||||
|
{
|
||||||
|
var len = input.length;
|
||||||
|
var res = "";
|
||||||
|
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
switch (input[i])
|
||||||
|
{
|
||||||
|
case '"':
|
||||||
|
res += '\\"';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\n':
|
||||||
|
res += '\\n';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\r':
|
||||||
|
res += '\\r';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\\':
|
||||||
|
res += '\\\\';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\/':
|
||||||
|
res += '\\/';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\b':
|
||||||
|
res += '\\b';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\f':
|
||||||
|
res += '\\f';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
res += '\\t';
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
res += input[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _egw_json_encode_simple(input)
|
||||||
{
|
{
|
||||||
switch (input.constructor)
|
switch (input.constructor)
|
||||||
{
|
{
|
||||||
case String:
|
case String:
|
||||||
return '"' + input + '"';
|
return '"' + _egw_json_escape_string(input) + '"';
|
||||||
|
|
||||||
case Number:
|
case Number:
|
||||||
return input.toString();
|
return input.toString();
|
||||||
@@ -33,7 +82,7 @@ function egw_json_encode(input)
|
|||||||
{
|
{
|
||||||
if (!input) return 'null';
|
if (!input) return 'null';
|
||||||
|
|
||||||
var simple_res = egw_json_encode_simple(input);
|
var simple_res = _egw_json_encode_simple(input);
|
||||||
if (simple_res == null)
|
if (simple_res == null)
|
||||||
{
|
{
|
||||||
switch (input.constructor)
|
switch (input.constructor)
|
||||||
@@ -50,7 +99,7 @@ function egw_json_encode(input)
|
|||||||
var buf = [];
|
var buf = [];
|
||||||
for (var k in input)
|
for (var k in input)
|
||||||
{
|
{
|
||||||
buf.push(egw_json_encode_simple(k) + ':' + egw_json_encode(input[k]));
|
buf.push(_egw_json_encode_simple(k) + ':' + egw_json_encode(input[k]));
|
||||||
}
|
}
|
||||||
return '{' + buf.join(',') + '}';
|
return '{' + buf.join(',') + '}';
|
||||||
|
|
||||||
@@ -129,6 +178,8 @@ egw_json_request.prototype.sendRequest = function(_async, _callback, _sender)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(request_obj);
|
||||||
|
|
||||||
//Send the request via the jquery AJAX interface to the server
|
//Send the request via the jquery AJAX interface to the server
|
||||||
$.ajax({url: this.url + '?menuaction=' + this.menuaction,
|
$.ajax({url: this.url + '?menuaction=' + this.menuaction,
|
||||||
async: is_async,
|
async: is_async,
|
||||||
|
Reference in New Issue
Block a user