1
0
Fork 0
This commit is contained in:
Jan Steemann 2012-11-22 11:49:02 +01:00
parent 530fc87a9a
commit c3602440d0
1 changed files with 11 additions and 27 deletions

View File

@ -1877,34 +1877,18 @@ function getTypedValue (value) {
// fallback: value is a string // fallback: value is a string
value = value + ''; value = value + '';
if (value.substr(0, 1) == '"' && value.substr(-1) == '"' ) { if (value.substr(0, 1) == '"') {
// remove quotes if (value.substr(-1) != '"') {
value = value.substr(1, value.length - 2); alert("You have entered an invalid string value. Please review and adjust it.");
throw "error";
var replacements = { 'b' : '\b', 'f' : '\f', 'n' : '\n', 'r' : '\r', 't' : '\t', '\\' : '\\', '"' : '"' }; }
var sanitised = ""; try {
var escaped = false; value = JSON.parse(value);
for (var i = 0; i < value.length; ++i) { }
var c = value.charAt(i); catch (e) {
if (escaped) { alert("You have entered an invalid string value. Please review and adjust it.");
escaped = false; throw e;
if (replacements[c] != '') {
sanitised += replacements[c];
}
else {
// invalid escape sequence
}
}
else {
if (c === '\\') {
escaped = true;
}
else {
sanitised += c;
}
}
} }
value = sanitised;
} }
return value; return value;
} }