Update utils.common.quote to escape unicode characters and inner escape sequences
This commit is contained in:
parent
0bfe796364
commit
fba49412c7
1 changed files with 18 additions and 1 deletions
|
@ -26,7 +26,24 @@ utils.common = {
|
|||
return list
|
||||
},
|
||||
quote: function (obj) {
|
||||
return JSON.stringify(obj)
|
||||
function escapeString (s) {
|
||||
let escaped = s.replace(/\\/g, '\\\\')
|
||||
.replace(/\"/g, '\\\"') // eslint-disable-line no-useless-escape
|
||||
.replace(/\0/g, '\\0')
|
||||
.replace(/\n/g, '\\n')
|
||||
.replace(/[^\0-~]/g, function (ch) {
|
||||
return '\\u' + ('000' + ch.charCodeAt(0).toString(16)).slice(-4)
|
||||
})
|
||||
|
||||
return '\"' + escaped + '\"' // eslint-disable-line no-useless-escape
|
||||
}
|
||||
|
||||
if (typeof s === 'string') {
|
||||
return escapeString(obj)
|
||||
} else {
|
||||
// For other things (such as numbers, |null|, and |undefined|), stringify
|
||||
return JSON.stringify(obj)
|
||||
}
|
||||
},
|
||||
b64encode: function (str) {
|
||||
// Unicode safe b64 encoding
|
||||
|
|
Loading…
Reference in a new issue