style: reformat all source code by prettier

This commit is contained in:
Zongmin Lei
2021-05-06 13:32:47 +08:00
parent 0b15109107
commit 901b771960
7 changed files with 40 additions and 32 deletions

32
dist/xss.js vendored
View File

@@ -479,7 +479,11 @@ if (typeof window !== "undefined") {
// using `xss` on the WebWorker, output `filterXSS` to the globals // using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() { function isWorkerEnv() {
return typeof self !== 'undefined' && typeof DedicatedWorkerGlobalScope !== 'undefined' && self instanceof DedicatedWorkerGlobalScope; return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
} }
if (isWorkerEnv()) { if (isWorkerEnv()) {
self.filterXSS = module.exports; self.filterXSS = module.exports;
@@ -573,11 +577,11 @@ function parseTag(html, onTag, escapeHtml) {
tagStart = false; tagStart = false;
continue; continue;
} }
if ((c === '"' || c === "'")) { if (c === '"' || c === "'") {
var i = 1; var i = 1;
var ic = html.charAt(currentPos - i); var ic = html.charAt(currentPos - i);
while ((ic.trim() === "") || (ic === "=")) { while (ic.trim() === "" || ic === "=") {
if (ic === "=") { if (ic === "=") {
quoteStart = c; quoteStart = c;
continue chariterator; continue chariterator;
@@ -736,7 +740,7 @@ exports.parseAttr = parseAttr;
},{"./util":4}],4:[function(require,module,exports){ },{"./util":4}],4:[function(require,module,exports){
module.exports = { module.exports = {
indexOf: function(arr, item) { indexOf: function (arr, item) {
var i, j; var i, j;
if (Array.prototype.indexOf) { if (Array.prototype.indexOf) {
return arr.indexOf(item); return arr.indexOf(item);
@@ -748,7 +752,7 @@ module.exports = {
} }
return -1; return -1;
}, },
forEach: function(arr, fn, scope) { forEach: function (arr, fn, scope) {
var i, j; var i, j;
if (Array.prototype.forEach) { if (Array.prototype.forEach) {
return arr.forEach(fn, scope); return arr.forEach(fn, scope);
@@ -757,17 +761,17 @@ module.exports = {
fn.call(scope, arr[i], i, arr); fn.call(scope, arr[i], i, arr);
} }
}, },
trim: function(str) { trim: function (str) {
if (String.prototype.trim) { if (String.prototype.trim) {
return str.trim(); return str.trim();
} }
return str.replace(/(^\s*)|(\s*$)/g, ""); return str.replace(/(^\s*)|(\s*$)/g, "");
}, },
spaceIndex: function(str) { spaceIndex: function (str) {
var reg = /\s|\n|\t/; var reg = /\s|\n|\t/;
var match = reg.exec(str); var match = reg.exec(str);
return match ? match.index : -1; return match ? match.index : -1;
} },
}; };
},{}],5:[function(require,module,exports){ },{}],5:[function(require,module,exports){
@@ -807,7 +811,7 @@ function getAttrs(html) {
if (i === -1) { if (i === -1) {
return { return {
html: "", html: "",
closing: html[html.length - 2] === "/" closing: html[html.length - 2] === "/",
}; };
} }
html = _.trim(html.slice(i + 1, -1)); html = _.trim(html.slice(i + 1, -1));
@@ -815,7 +819,7 @@ function getAttrs(html) {
if (isClosing) html = _.trim(html.slice(0, -1)); if (isClosing) html = _.trim(html.slice(0, -1));
return { return {
html: html, html: html,
closing: isClosing closing: isClosing,
}; };
} }
@@ -877,7 +881,7 @@ function FilterXSS(options) {
* @param {String} html * @param {String} html
* @return {String} * @return {String}
*/ */
FilterXSS.prototype.process = function(html) { FilterXSS.prototype.process = function (html) {
// compatible with the input // compatible with the input
html = html || ""; html = html || "";
html = html.toString(); html = html.toString();
@@ -916,12 +920,12 @@ FilterXSS.prototype.process = function(html) {
var retHtml = parseTag( var retHtml = parseTag(
html, html,
function(sourcePosition, position, tag, html, isClosing) { function (sourcePosition, position, tag, html, isClosing) {
var info = { var info = {
sourcePosition: sourcePosition, sourcePosition: sourcePosition,
position: position, position: position,
isClosing: isClosing, isClosing: isClosing,
isWhite: whiteList.hasOwnProperty(tag) isWhite: whiteList.hasOwnProperty(tag),
}; };
// call `onTag()` // call `onTag()`
@@ -935,7 +939,7 @@ FilterXSS.prototype.process = function(html) {
var attrs = getAttrs(html); var attrs = getAttrs(html);
var whiteAttrList = whiteList[tag]; var whiteAttrList = whiteList[tag];
var attrsHtml = parseAttr(attrs.html, function(name, value) { var attrsHtml = parseAttr(attrs.html, function (name, value) {
// call `onTagAttr()` // call `onTagAttr()`
var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1; var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
var ret = onTagAttr(tag, name, value, isWhiteAttr); var ret = onTagAttr(tag, name, value, isWhiteAttr);

View File

@@ -9,7 +9,7 @@ var readline = require("readline");
var rl = readline.createInterface({ var rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout,
}); });
console.log('Enter a blank line to do xss(), enter "@quit" to exit.\n'); console.log('Enter a blank line to do xss(), enter "@quit" to exit.\n');
@@ -31,7 +31,7 @@ function setPrompt(line) {
setPrompt(1); setPrompt(1);
var html = []; var html = [];
rl.on("line", function(line) { rl.on("line", function (line) {
if (line === "@quit") return process.exit(); if (line === "@quit") return process.exit();
if (line === "") { if (line === "") {
console.log(""); console.log("");

View File

@@ -33,7 +33,11 @@ if (typeof window !== "undefined") {
// using `xss` on the WebWorker, output `filterXSS` to the globals // using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() { function isWorkerEnv() {
return typeof self !== 'undefined' && typeof DedicatedWorkerGlobalScope !== 'undefined' && self instanceof DedicatedWorkerGlobalScope; return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
} }
if (isWorkerEnv()) { if (isWorkerEnv()) {
self.filterXSS = module.exports; self.filterXSS = module.exports;

View File

@@ -85,11 +85,11 @@ function parseTag(html, onTag, escapeHtml) {
tagStart = false; tagStart = false;
continue; continue;
} }
if ((c === '"' || c === "'")) { if (c === '"' || c === "'") {
var i = 1; var i = 1;
var ic = html.charAt(currentPos - i); var ic = html.charAt(currentPos - i);
while ((ic.trim() === "") || (ic === "=")) { while (ic.trim() === "" || ic === "=") {
if (ic === "=") { if (ic === "=") {
quoteStart = c; quoteStart = c;
continue chariterator; continue chariterator;

View File

@@ -1,5 +1,5 @@
module.exports = { module.exports = {
indexOf: function(arr, item) { indexOf: function (arr, item) {
var i, j; var i, j;
if (Array.prototype.indexOf) { if (Array.prototype.indexOf) {
return arr.indexOf(item); return arr.indexOf(item);
@@ -11,7 +11,7 @@ module.exports = {
} }
return -1; return -1;
}, },
forEach: function(arr, fn, scope) { forEach: function (arr, fn, scope) {
var i, j; var i, j;
if (Array.prototype.forEach) { if (Array.prototype.forEach) {
return arr.forEach(fn, scope); return arr.forEach(fn, scope);
@@ -20,15 +20,15 @@ module.exports = {
fn.call(scope, arr[i], i, arr); fn.call(scope, arr[i], i, arr);
} }
}, },
trim: function(str) { trim: function (str) {
if (String.prototype.trim) { if (String.prototype.trim) {
return str.trim(); return str.trim();
} }
return str.replace(/(^\s*)|(\s*$)/g, ""); return str.replace(/(^\s*)|(\s*$)/g, "");
}, },
spaceIndex: function(str) { spaceIndex: function (str) {
var reg = /\s|\n|\t/; var reg = /\s|\n|\t/;
var match = reg.exec(str); var match = reg.exec(str);
return match ? match.index : -1; return match ? match.index : -1;
} },
}; };

View File

@@ -34,7 +34,7 @@ function getAttrs(html) {
if (i === -1) { if (i === -1) {
return { return {
html: "", html: "",
closing: html[html.length - 2] === "/" closing: html[html.length - 2] === "/",
}; };
} }
html = _.trim(html.slice(i + 1, -1)); html = _.trim(html.slice(i + 1, -1));
@@ -42,7 +42,7 @@ function getAttrs(html) {
if (isClosing) html = _.trim(html.slice(0, -1)); if (isClosing) html = _.trim(html.slice(0, -1));
return { return {
html: html, html: html,
closing: isClosing closing: isClosing,
}; };
} }
@@ -104,7 +104,7 @@ function FilterXSS(options) {
* @param {String} html * @param {String} html
* @return {String} * @return {String}
*/ */
FilterXSS.prototype.process = function(html) { FilterXSS.prototype.process = function (html) {
// compatible with the input // compatible with the input
html = html || ""; html = html || "";
html = html.toString(); html = html.toString();
@@ -143,12 +143,12 @@ FilterXSS.prototype.process = function(html) {
var retHtml = parseTag( var retHtml = parseTag(
html, html,
function(sourcePosition, position, tag, html, isClosing) { function (sourcePosition, position, tag, html, isClosing) {
var info = { var info = {
sourcePosition: sourcePosition, sourcePosition: sourcePosition,
position: position, position: position,
isClosing: isClosing, isClosing: isClosing,
isWhite: whiteList.hasOwnProperty(tag) isWhite: whiteList.hasOwnProperty(tag),
}; };
// call `onTag()` // call `onTag()`
@@ -162,7 +162,7 @@ FilterXSS.prototype.process = function(html) {
var attrs = getAttrs(html); var attrs = getAttrs(html);
var whiteAttrList = whiteList[tag]; var whiteAttrList = whiteList[tag];
var attrsHtml = parseAttr(attrs.html, function(name, value) { var attrsHtml = parseAttr(attrs.html, function (name, value) {
// call `onTagAttr()` // call `onTagAttr()`
var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1; var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
var ret = onTagAttr(tag, name, value, isWhiteAttr); var ret = onTagAttr(tag, name, value, isWhiteAttr);

View File

@@ -21,7 +21,7 @@ console.log(
onTag(tag: string, html: string, options: {}): string { onTag(tag: string, html: string, options: {}): string {
return html; return html;
}, },
css: false css: false,
}) })
); );
@@ -34,7 +34,7 @@ xss.filterXSS("hello", {
onTag(tag, html, options) { onTag(tag, html, options) {
return html; return html;
}, },
onIgnoreTag(tag, html) {} onIgnoreTag(tag, html) {},
}); });
interface ICustomWhiteList extends XSS.IWhiteList { interface ICustomWhiteList extends XSS.IWhiteList {