Only escape minimal characters and allow HTML escapes

This commit is contained in:
pyoor 2018-08-02 14:26:17 -04:00
parent 195411fe8d
commit 80f16a4aaf
1 changed files with 14 additions and 3 deletions

View File

@ -30,11 +30,22 @@ class common extends utils {
return list
}
static quote (s) {
/**
* Escape and quote a string
* @param s {string} - String to be quoted
* @param html {boolean} - Identifies whether the string must be HTML safe
* @returns {*}
*/
static quote (s, html = false) {
const options = {
minimal: true,
isScriptContext: html
}
if (typeof s === 'string') {
return `'${jsesc(s)}'`
return `'${jsesc(s, options)}'`
} else {
return jsesc(s)
return jsesc(s, options)
}
}