|
| 1 | +const { parse } = require('@test/test-target'); |
| 2 | + |
| 3 | +describe('issue 218', function () { |
| 4 | + it('attribute value contains quote should be parsed correct', function () { |
| 5 | + const html = `<html> |
| 6 | + <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> |
| 7 | + <div id="e" title='"world"' color="red">expected</div> |
| 8 | + <div id="a" title='"world"' onClick='alert("hello")' color="red">actual</div> |
| 9 | +</html>`; |
| 10 | + const root = parse(html); |
| 11 | + root.toString().should.eql(`<html> |
| 12 | + <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> |
| 13 | + <div id="e" title='"world"' color="red">expected</div> |
| 14 | + <div id="a" title='"world"' onClick='alert("hello")' color="red">actual</div> |
| 15 | +</html>`); |
| 16 | + root.querySelector('#e').setAttribute('onClick', "alert('hello')"); |
| 17 | + |
| 18 | + root.toString().should.eql(`<html> |
| 19 | + <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> |
| 20 | + <div id="e" title=""world"" color="red" onClick="alert('hello')">expected</div> |
| 21 | + <div id="a" title='"world"' onClick='alert("hello")' color="red">actual</div> |
| 22 | +</html>`); |
| 23 | + |
| 24 | + // root.querySelector('#a').setAttribute('title', '"replaced"'); |
| 25 | + root.querySelector('#a').removeAttribute('color'); // FIXME |
| 26 | + |
| 27 | + root.toString().should.eql(`<html> |
| 28 | + <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> |
| 29 | + <div id="e" title=""world"" color="red" onClick="alert('hello')">expected</div> |
| 30 | + <div id="a" title=""world"" onClick="alert("hello")">actual</div> |
| 31 | +</html>`); |
| 32 | + root.querySelector('#a').setAttribute('title', '"replaced"'); |
| 33 | + root.toString().should.eql(`<html> |
| 34 | + <div id="_" title='"world"' onClick='alert("hello")' color="red">nochange</div> |
| 35 | + <div id="e" title=""world"" color="red" onClick="alert('hello')">expected</div> |
| 36 | + <div id="a" title=""replaced"" onClick="alert("hello")">actual</div> |
| 37 | +</html>`); |
| 38 | + }); |
| 39 | + it('should escape newlines to html entities', function () { |
| 40 | + const root = parse('<p></p>'); |
| 41 | + const p = root.firstChild; |
| 42 | + p.setAttribute('a', '1\n2'); |
| 43 | + p.getAttribute('a').should.eql('1\n2'); |
| 44 | + p.toString().should.eql('<p a="1\n2"></p>'); |
| 45 | + }); |
| 46 | +}); |
0 commit comments