This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* explicitly require full URLs (ftp|https?://...) * list the URI attributes * remove a lot of unneeded attributes
- Loading branch information
Showing
2 changed files
with
90 additions
and
74 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ describe('HTML', function(){ | |
|
||
it('should echo html', function(){ | ||
expectHTML('hello<b class="1\'23" align=\'""\'>world</b>.'). | ||
toEqual('hello<b class="1\'23" align="""">world</b>.'); | ||
toEqual('hello<b class="1\'23" align="""">world</b>.'); | ||
}); | ||
|
||
it('should remove script', function(){ | ||
|
@@ -49,9 +49,15 @@ describe('HTML', function(){ | |
expectHTML('a<my:hr/><my:div>b</my:div>c').toEqual('abc'); | ||
}); | ||
|
||
it('should handle entities', function(){ | ||
var everything = '<div id="!@#$%^&*()_+-={}[]:";\'<>?,./`~ ħ">' + | ||
'!@#$%^&*()_+-={}[]:";\'<>?,./`~ ħ</div>'; | ||
expectHTML(everything).toEqual(everything); | ||
}); | ||
|
||
it('should handle improper html', function(){ | ||
expectHTML('< div id="</div>" alt=abc href=\'"\' >text< /div>'). | ||
toEqual('<div id="</div>" alt="abc" href=""">text</div>'); | ||
expectHTML('< div id="</div>" alt=abc dir=\'"\' >text< /div>'). | ||
toEqual('<div id="</div>" alt="abc" dir=""">text</div>'); | ||
}); | ||
|
||
it('should handle improper html2', function(){ | ||
|
@@ -81,19 +87,14 @@ describe('HTML', function(){ | |
expect(html).toEqual('a<div>&</div>c'); | ||
}); | ||
|
||
it('should not double escape entities', function(){ | ||
writer.chars(' ><'); | ||
expect(html).toEqual(' ><'); | ||
}); | ||
|
||
it('should escape IE script', function(){ | ||
writer.chars('&{}'); | ||
expect(html).toEqual('&{}'); | ||
writer.chars('&<>{}'); | ||
expect(html).toEqual('&<>{}'); | ||
}); | ||
|
||
it('should escape attributes', function(){ | ||
writer.start('div', {id:'\"\'<>'}); | ||
expect(html).toEqual('<div id=""\'<>">'); | ||
writer.start('div', {id:'!@#$%^&*()_+-={}[]:";\'<>?,./`~ \n\0\r\u0127'}); | ||
expect(html).toEqual('<div id="!@#$%^&*()_+-={}[]:";\'<>?,./`~ � ħ">'); | ||
}); | ||
|
||
it('should ignore missformed elements', function(){ | ||
|
@@ -105,20 +106,40 @@ describe('HTML', function(){ | |
writer.start('div', {unknown:""}); | ||
expect(html).toEqual('<div>'); | ||
}); | ||
|
||
describe('isUri', function(){ | ||
|
||
function isUri(value) { | ||
return value.match(URI_REGEXP); | ||
} | ||
|
||
it('should be URI', function(){ | ||
expect(isUri('http://abc')).toBeTruthy(); | ||
expect(isUri('https://abc')).toBeTruthy(); | ||
expect(isUri('ftp://abc')).toBeTruthy(); | ||
expect(isUri('mailto:[email protected]')).toBeTruthy(); | ||
expect(isUri('#anchor')).toBeTruthy(); | ||
}); | ||
|
||
it('should not be UIR', function(){ | ||
expect(isUri('')).toBeFalsy(); | ||
expect(isUri('javascript:alert')).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('javascript URL attribute', function(){ | ||
beforeEach(function(){ | ||
this.addMatchers({ | ||
toBeValidUrl: function(){ | ||
return !isJavaScriptUrl(this.actual); | ||
return URI_REGEXP.exec(this.actual); | ||
} | ||
}); | ||
}); | ||
|
||
it('should ignore javascript:', function(){ | ||
expect('JavaScript:abc').not.toBeValidUrl(); | ||
expect(' \n Java\n Script:abc').not.toBeValidUrl(); | ||
expect('JavaScript/my.js').toBeValidUrl(); | ||
expect('http://JavaScript/my.js').toBeValidUrl(); | ||
}); | ||
|
||
it('should ignore dec encoded javascript:', function(){ | ||
|