Skip to content

Commit

Permalink
style: reformat all source code by prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
leizongmin committed May 6, 2021
1 parent 0b15109 commit 901b771
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 32 deletions.
32 changes: 18 additions & 14 deletions dist/xss.js
Expand Up @@ -479,7 +479,11 @@ if (typeof window !== "undefined") {

// using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() {
return typeof self !== 'undefined' && typeof DedicatedWorkerGlobalScope !== 'undefined' && self instanceof DedicatedWorkerGlobalScope;
return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
}
if (isWorkerEnv()) {
self.filterXSS = module.exports;
Expand Down Expand Up @@ -573,11 +577,11 @@ function parseTag(html, onTag, escapeHtml) {
tagStart = false;
continue;
}
if ((c === '"' || c === "'")) {
if (c === '"' || c === "'") {
var i = 1;
var ic = html.charAt(currentPos - i);

while ((ic.trim() === "") || (ic === "=")) {
while (ic.trim() === "" || ic === "=") {
if (ic === "=") {
quoteStart = c;
continue chariterator;
Expand Down Expand Up @@ -736,7 +740,7 @@ exports.parseAttr = parseAttr;

},{"./util":4}],4:[function(require,module,exports){
module.exports = {
indexOf: function(arr, item) {
indexOf: function (arr, item) {
var i, j;
if (Array.prototype.indexOf) {
return arr.indexOf(item);
Expand All @@ -748,7 +752,7 @@ module.exports = {
}
return -1;
},
forEach: function(arr, fn, scope) {
forEach: function (arr, fn, scope) {
var i, j;
if (Array.prototype.forEach) {
return arr.forEach(fn, scope);
Expand All @@ -757,17 +761,17 @@ module.exports = {
fn.call(scope, arr[i], i, arr);
}
},
trim: function(str) {
trim: function (str) {
if (String.prototype.trim) {
return str.trim();
}
return str.replace(/(^\s*)|(\s*$)/g, "");
},
spaceIndex: function(str) {
spaceIndex: function (str) {
var reg = /\s|\n|\t/;
var match = reg.exec(str);
return match ? match.index : -1;
}
},
};

},{}],5:[function(require,module,exports){
Expand Down Expand Up @@ -807,15 +811,15 @@ function getAttrs(html) {
if (i === -1) {
return {
html: "",
closing: html[html.length - 2] === "/"
closing: html[html.length - 2] === "/",
};
}
html = _.trim(html.slice(i + 1, -1));
var isClosing = html[html.length - 1] === "/";
if (isClosing) html = _.trim(html.slice(0, -1));
return {
html: html,
closing: isClosing
closing: isClosing,
};
}

Expand Down Expand Up @@ -877,7 +881,7 @@ function FilterXSS(options) {
* @param {String} html
* @return {String}
*/
FilterXSS.prototype.process = function(html) {
FilterXSS.prototype.process = function (html) {
// compatible with the input
html = html || "";
html = html.toString();
Expand Down Expand Up @@ -916,12 +920,12 @@ FilterXSS.prototype.process = function(html) {

var retHtml = parseTag(
html,
function(sourcePosition, position, tag, html, isClosing) {
function (sourcePosition, position, tag, html, isClosing) {
var info = {
sourcePosition: sourcePosition,
position: position,
isClosing: isClosing,
isWhite: whiteList.hasOwnProperty(tag)
isWhite: whiteList.hasOwnProperty(tag),
};

// call `onTag()`
Expand All @@ -935,7 +939,7 @@ FilterXSS.prototype.process = function(html) {

var attrs = getAttrs(html);
var whiteAttrList = whiteList[tag];
var attrsHtml = parseAttr(attrs.html, function(name, value) {
var attrsHtml = parseAttr(attrs.html, function (name, value) {
// call `onTagAttr()`
var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
var ret = onTagAttr(tag, name, value, isWhiteAttr);
Expand Down
4 changes: 2 additions & 2 deletions lib/cli.js
Expand Up @@ -9,7 +9,7 @@ var readline = require("readline");

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
});

console.log('Enter a blank line to do xss(), enter "@quit" to exit.\n');
Expand All @@ -31,7 +31,7 @@ function setPrompt(line) {
setPrompt(1);

var html = [];
rl.on("line", function(line) {
rl.on("line", function (line) {
if (line === "@quit") return process.exit();
if (line === "") {
console.log("");
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -33,7 +33,11 @@ if (typeof window !== "undefined") {

// using `xss` on the WebWorker, output `filterXSS` to the globals
function isWorkerEnv() {
return typeof self !== 'undefined' && typeof DedicatedWorkerGlobalScope !== 'undefined' && self instanceof DedicatedWorkerGlobalScope;
return (
typeof self !== "undefined" &&
typeof DedicatedWorkerGlobalScope !== "undefined" &&
self instanceof DedicatedWorkerGlobalScope
);
}
if (isWorkerEnv()) {
self.filterXSS = module.exports;
Expand Down
4 changes: 2 additions & 2 deletions lib/parser.js
Expand Up @@ -85,11 +85,11 @@ function parseTag(html, onTag, escapeHtml) {
tagStart = false;
continue;
}
if ((c === '"' || c === "'")) {
if (c === '"' || c === "'") {
var i = 1;
var ic = html.charAt(currentPos - i);

while ((ic.trim() === "") || (ic === "=")) {
while (ic.trim() === "" || ic === "=") {
if (ic === "=") {
quoteStart = c;
continue chariterator;
Expand Down
10 changes: 5 additions & 5 deletions lib/util.js
@@ -1,5 +1,5 @@
module.exports = {
indexOf: function(arr, item) {
indexOf: function (arr, item) {
var i, j;
if (Array.prototype.indexOf) {
return arr.indexOf(item);
Expand All @@ -11,7 +11,7 @@ module.exports = {
}
return -1;
},
forEach: function(arr, fn, scope) {
forEach: function (arr, fn, scope) {
var i, j;
if (Array.prototype.forEach) {
return arr.forEach(fn, scope);
Expand All @@ -20,15 +20,15 @@ module.exports = {
fn.call(scope, arr[i], i, arr);
}
},
trim: function(str) {
trim: function (str) {
if (String.prototype.trim) {
return str.trim();
}
return str.replace(/(^\s*)|(\s*$)/g, "");
},
spaceIndex: function(str) {
spaceIndex: function (str) {
var reg = /\s|\n|\t/;
var match = reg.exec(str);
return match ? match.index : -1;
}
},
};
12 changes: 6 additions & 6 deletions lib/xss.js
Expand Up @@ -34,15 +34,15 @@ function getAttrs(html) {
if (i === -1) {
return {
html: "",
closing: html[html.length - 2] === "/"
closing: html[html.length - 2] === "/",
};
}
html = _.trim(html.slice(i + 1, -1));
var isClosing = html[html.length - 1] === "/";
if (isClosing) html = _.trim(html.slice(0, -1));
return {
html: html,
closing: isClosing
closing: isClosing,
};
}

Expand Down Expand Up @@ -104,7 +104,7 @@ function FilterXSS(options) {
* @param {String} html
* @return {String}
*/
FilterXSS.prototype.process = function(html) {
FilterXSS.prototype.process = function (html) {
// compatible with the input
html = html || "";
html = html.toString();
Expand Down Expand Up @@ -143,12 +143,12 @@ FilterXSS.prototype.process = function(html) {

var retHtml = parseTag(
html,
function(sourcePosition, position, tag, html, isClosing) {
function (sourcePosition, position, tag, html, isClosing) {
var info = {
sourcePosition: sourcePosition,
position: position,
isClosing: isClosing,
isWhite: whiteList.hasOwnProperty(tag)
isWhite: whiteList.hasOwnProperty(tag),
};

// call `onTag()`
Expand All @@ -162,7 +162,7 @@ FilterXSS.prototype.process = function(html) {

var attrs = getAttrs(html);
var whiteAttrList = whiteList[tag];
var attrsHtml = parseAttr(attrs.html, function(name, value) {
var attrsHtml = parseAttr(attrs.html, function (name, value) {
// call `onTagAttr()`
var isWhiteAttr = _.indexOf(whiteAttrList, name) !== -1;
var ret = onTagAttr(tag, name, value, isWhiteAttr);
Expand Down
4 changes: 2 additions & 2 deletions typings/xss-tests.ts
Expand Up @@ -21,7 +21,7 @@ console.log(
onTag(tag: string, html: string, options: {}): string {
return html;
},
css: false
css: false,
})
);

Expand All @@ -34,7 +34,7 @@ xss.filterXSS("hello", {
onTag(tag, html, options) {
return html;
},
onIgnoreTag(tag, html) {}
onIgnoreTag(tag, html) {},
});

interface ICustomWhiteList extends XSS.IWhiteList {
Expand Down

0 comments on commit 901b771

Please sign in to comment.