@@ -8,17 +8,15 @@ Authors: Aditya Mahendrakar <maditya@yahoo-inc.com>
88 Albert Yu <albertyu@yahoo-inc.com>
99 Adonis Fung <adon@yahoo-inc.com>
1010*/
11-
12-
1311( function ( ) {
1412
1513 require ( "mocha" ) ;
16-
1714 var assert = require ( "assert" ) ,
1815 testVectors = require ( "../test-vectors.js" ) ,
1916 html5secVectors = testVectors . html5secVectors ,
2017 generalVectors = testVectors . generalVectors ,
2118 Purifier = require ( "../../src/html-purify" ) ;
19+
2220 describe ( 'HTML Purify' , function ( ) {
2321
2422 it ( 'should allow whitelisted tags and attributes' , function ( ) {
@@ -49,63 +47,61 @@ Authors: Aditya Mahendrakar <maditya@yahoo-inc.com>
4947 it ( 'should allow self-closing tags' , function ( ) {
5048 var html = "<br /> hello world </br>"
5149 var output = ( new Purifier ( ) ) . purify ( html ) ;
52- console . log ( output ) ;
50+ console . log ( output ) ;
5351 assert . equal ( output , '<br /> hello world </br>' ) ;
5452 } ) ;
53+
5554 it ( 'should handle href attributes' , function ( ) {
5655 var html = "<a href=\"http://www.yahoo.com\">yahoo</a>" ;
5756 var output = ( new Purifier ( ) ) . purify ( html ) ;
58- console . log ( output ) ;
57+ console . log ( output ) ;
5958 assert . equal ( output , '<a href="http://www.yahoo.com">yahoo</a>' ) ;
6059 } ) ;
60+
6161 it ( 'should handle js in href attributes' , function ( ) {
6262 var html = "<a href=\"javascript:alert(1)\">yahoo</a>" ;
6363 var output = ( new Purifier ( ) ) . purify ( html ) ;
64- console . log ( output ) ;
64+ console . log ( output ) ;
6565 assert . equal ( output , '<a href="x-javascript:alert(1)">yahoo</a>' ) ;
6666 } ) ;
6767
68- it ( 'should strip attributes in the end tag' , function ( ) {
68+ it ( 'should strip attributes in the end tag' , function ( ) {
6969 var html = "<h1 dir = \"asd\">hello</h1 id=\"bar\">"
7070 var output = ( new Purifier ( ) ) . purify ( html ) ;
71- console . log ( output ) ;
71+ console . log ( output ) ;
7272 assert . equal ( output , '<h1 dir=\"asd\">hello</h1>' ) ;
7373 } ) ;
7474
7575 it ( 'should handle characters between attributes correctly' , function ( ) {
7676 var html = "<h1 label dir = \"asd\" evil1 defer \"evil2\" evil3 evil4=\"asdasd\" icon 'evil5>hello</h1>"
7777 var output = ( new Purifier ( ) ) . purify ( html ) ;
78- console . log ( output ) ;
78+ console . log ( output ) ;
7979 assert . equal ( output , '<h1 label dir=\"asd\" defer icon>hello</h1>' ) ;
8080 } ) ;
8181
8282 it ( 'should allow style attribute if the css is valid' , function ( ) {
8383 var html = "<div style=\"color:#0000FF\">"
8484 var output = ( new Purifier ( ) ) . purify ( html ) ;
85- console . log ( output ) ;
85+ console . log ( output ) ;
8686 assert . equal ( output , '<div style=\"color:#0000FF\">' ) ;
8787
8888 // invalid css
89- html = "<div style=\"color;foobar\">"
90- output = ( new Purifier ( ) ) . purify ( html ) ;
91- console . log ( output ) ;
92- assert . equal ( output , '<div>' ) ;
89+ html = "<div style=\"color;foobar\">" ;
90+ output = ( new Purifier ( ) ) . purify ( html ) ;
91+ console . log ( output ) ;
92+ assert . equal ( output , '<div>' ) ;
9393 } ) ;
9494
9595 it ( 'should handle additional vectors' , function ( ) {
9696 var output , i , vector ;
9797 for ( var i = 0 ; i < generalVectors . length ; i ++ ) {
98- vector = generalVectors [ i ] . input ;
99- output = ( new Purifier ( ) ) . purify ( vector ) ;
100- console . log ( "*****" + generalVectors [ i ] . id + "*****" ) ;
101- console . log ( "input ==> " + vector ) ;
102- console . log ( "output ==> " + output ) ;
103- assert . equal ( output , generalVectors [ i ] . output ) ;
98+ vector = generalVectors [ i ] . input ;
99+ output = ( new Purifier ( ) ) . purify ( vector ) ;
100+ console . log ( "*****" + generalVectors [ i ] . id + "*****" ) ;
101+ console . log ( "input ==> " + vector ) ;
102+ console . log ( "output ==> " + output ) ;
103+ assert . equal ( output , generalVectors [ i ] . output ) ;
104104 }
105-
106105 } ) ;
107-
108-
109106 } ) ;
110-
111107} ( ) ) ;
0 commit comments