This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from neraliu/comment-the-code
add the comment to the logic of the switch case.
- Loading branch information
Showing
2 changed files
with
33 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,15 @@ Authors: Aditya Mahendrakar <[email protected]> | |
Albert Yu <[email protected]> | ||
Adonis Fung <[email protected]> | ||
*/ | ||
|
||
|
||
(function () { | ||
|
||
require("mocha"); | ||
|
||
var assert = require("assert"), | ||
testVectors = require("../test-vectors.js"), | ||
html5secVectors = testVectors.html5secVectors, | ||
generalVectors = testVectors.generalVectors, | ||
Purifier = require("../../src/html-purify"); | ||
|
||
describe('HTML Purify', function() { | ||
|
||
it('should allow whitelisted tags and attributes', function(){ | ||
|
@@ -49,63 +47,61 @@ Authors: Aditya Mahendrakar <[email protected]> | |
it('should allow self-closing tags', function(){ | ||
var html = "<br /> hello world </br>" | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<br /> hello world </br>'); | ||
}); | ||
|
||
it('should handle href attributes', function(){ | ||
var html = "<a href=\"http://www.yahoo.com\">yahoo</a>"; | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<a href="http://www.yahoo.com">yahoo</a>'); | ||
}); | ||
|
||
it('should handle js in href attributes', function(){ | ||
var html = "<a href=\"javascript:alert(1)\">yahoo</a>"; | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<a href="x-javascript:alert(1)">yahoo</a>'); | ||
}); | ||
|
||
it('should strip attributes in the end tag', function(){ | ||
it('should strip attributes in the end tag', function(){ | ||
var html = "<h1 dir = \"asd\">hello</h1 id=\"bar\">" | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<h1 dir=\"asd\">hello</h1>'); | ||
}); | ||
|
||
it('should handle characters between attributes correctly', function(){ | ||
var html = "<h1 label dir = \"asd\" evil1 defer \"evil2\" evil3 evil4=\"asdasd\" icon 'evil5>hello</h1>" | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<h1 label dir=\"asd\" defer icon>hello</h1>'); | ||
}); | ||
|
||
it('should allow style attribute if the css is valid', function(){ | ||
var html = "<div style=\"color:#0000FF\">" | ||
var output = (new Purifier()).purify(html); | ||
console.log(output); | ||
console.log(output); | ||
assert.equal(output, '<div style=\"color:#0000FF\">'); | ||
|
||
// invalid css | ||
html = "<div style=\"color;foobar\">" | ||
output = (new Purifier()).purify(html); | ||
console.log(output); | ||
assert.equal(output, '<div>'); | ||
html = "<div style=\"color;foobar\">"; | ||
output = (new Purifier()).purify(html); | ||
console.log(output); | ||
assert.equal(output, '<div>'); | ||
}); | ||
|
||
it('should handle additional vectors', function(){ | ||
var output, i, vector; | ||
for (var i = 0; i < generalVectors.length; i++) { | ||
vector = generalVectors[i].input; | ||
output = (new Purifier()).purify(vector); | ||
console.log("*****" + generalVectors[i].id + "*****"); | ||
console.log("input ==> " + vector); | ||
console.log("output ==> " + output); | ||
assert.equal(output, generalVectors[i].output); | ||
vector = generalVectors[i].input; | ||
output = (new Purifier()).purify(vector); | ||
console.log("*****" + generalVectors[i].id + "*****"); | ||
console.log("input ==> " + vector); | ||
console.log("output ==> " + output); | ||
assert.equal(output, generalVectors[i].output); | ||
} | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
}()); |