You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
4.7 KiB
89 lines
4.7 KiB
var wows = require('vows');
|
|
var assert = require('assert');
|
|
var DOMParser = require('xmldom').DOMParser;
|
|
var XMLSerializer = require('xmldom').XMLSerializer;
|
|
var parser = new DOMParser();
|
|
// Create a Test Suite
|
|
wows.describe('html normalizer').addBatch({
|
|
'text & <': function () {
|
|
var dom = new DOMParser().parseFromString('<div>&<123&456<789;&&</div>','text/html');
|
|
console.assert(dom == '<div>&<123&456<789;&&</div>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<div><123e>&<a<br/></div>','text/html');
|
|
console.assert(dom == '<div><123e>&<a<br/></div>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<div> © ©</div>','text/html');
|
|
console.assert(dom == '<div>\u00a0\u00a9&nbsp&copy</div>',dom+'')
|
|
|
|
|
|
var dom = new DOMParser().parseFromString('<html xmlns:x="1"><body/></html>','text/html');
|
|
console.assert(dom == '<html xmlns:x="1"><body></body></html>',dom+'')
|
|
},
|
|
'attr': function () {
|
|
var dom = new DOMParser().parseFromString('<html test="a<b && a>b && \'&&&\'"/>','text/html');
|
|
console.assert(dom == '<html test="a<b && a>b && \'&&&\'"></html>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<div test="alert(\'<br/>\')"/>','text/html');
|
|
console.assert(dom == '<div test="alert(\'<br/>\')"></div>',dom+'')
|
|
var dom = new DOMParser().parseFromString('<div test="a<b&&a< c && a>d"></div>','text/html');
|
|
console.assert(dom == '<div test="a<b&&a< c && a>d"></div>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<div a=& bb c d=123&&456/>','text/html');
|
|
console.assert(dom == '<div a="&" bb="bb" c="c" d="123&&456"></div>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<div a=& a="&\'\'" b/>','text/html');
|
|
console.assert(dom == '<div a="&\'\'" b="b"></div>',dom+'')
|
|
},
|
|
'attrQute': function () {
|
|
var dom = new DOMParser().parseFromString('<html test="123"/>','text/html');
|
|
console.assert(dom == '<html test="123"></html>',dom+'')
|
|
|
|
// var dom = new DOMParser().parseFromString('<r><Label onClick="doClick..>Hello, World</Label></r>','text/html');
|
|
// console.assert(dom == '<r><Label onClick="doClick..">Hello, World</Label></r>',dom+'!!')
|
|
//
|
|
var dom = new DOMParser().parseFromString('<Label onClick=doClick..">Hello, World</Label>','text/html');
|
|
console.assert(dom == '<Label onClick="doClick..">Hello, World</Label>',dom+'')
|
|
},
|
|
"unclosed":function(){
|
|
var dom = new DOMParser().parseFromString('<html><meta><link><img><br><hr><input></html>','text/html');
|
|
console.assert(dom == '<html><meta/><link/><img/><br/><hr/><input/></html>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<html title =1/2></html>','text/html');
|
|
console.assert(dom == '<html title="1/2"></html>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<html title= 1/>','text/html');
|
|
console.assert(dom == '<html title="1"></html>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<html title = 1/>','text/html');
|
|
console.assert(dom == '<html title="1"></html>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<html title/>','text/html');
|
|
console.assert(dom == '<html title="title"></html>',dom+'')
|
|
|
|
|
|
|
|
var dom = new DOMParser().parseFromString('<html><meta><link><img><br><hr><input></html>','text/html');
|
|
console.assert(dom == '<html><meta/><link/><img/><br/><hr/><input/></html>',dom+'')
|
|
|
|
|
|
},
|
|
'script': function () {
|
|
var dom = new DOMParser().parseFromString('<script>alert(a<b&&c?"<br>":">>");</script>','text/html');
|
|
console.assert(dom == '<script>alert(a<b&&c?"<br>":">>");</script>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<script>alert(a<b&&c?"<br>":">>");</script>','text/xml');
|
|
console.assert(dom == '<script>alert(a<b&&c?"<br/>":">>");</script>',dom+'')
|
|
|
|
var dom = new DOMParser().parseFromString('<script>alert(a<b&&c?"<br/>":">>");</script>','text/html');
|
|
console.assert(dom == '<script>alert(a<b&&c?"<br/>":">>");</script>',dom+'')
|
|
|
|
},
|
|
'textarea': function () {
|
|
var dom = new DOMParser().parseFromString('<textarea>alert(a<b&&c?"<br>":">>");</textarea>','text/html');
|
|
console.assert(dom == '<textarea>alert(a<b&&c?"<br>":">>");</textarea>',dom+'')
|
|
|
|
|
|
var dom = new DOMParser().parseFromString('<textarea>alert(a<b&&c?"<br>":">>");</textarea>','text/xml');
|
|
console.assert(dom == '<textarea>alert(a<b&&c?"<br/>":">>");</textarea>',dom+'')
|
|
}
|
|
}).run(); |