node-htmlparser icon indicating copy to clipboard operation
node-htmlparser copied to clipboard

1.x: HTML comment delimiters inside <script> ends the tag

Open papandreou opened this issue 13 years ago • 1 comments

var rawHtml = '<script>document.write("<!--hello-->");</script>',
    htmlparser = require('./lib/htmlparser'),
    handler = new htmlparser.DefaultHandler(),
    parser = new htmlparser.Parser(handler);
parser.parseComplete(rawHtml);
console.warn(require('util').inspect(handler.dom, false, null));

Output:

[ { raw: 'script',
    data: 'script',
    type: 'script',
    name: 'script',
    children: 
     [ { raw: 'document.write("',
         data: 'document.write("',
         type: 'text' },
       { raw: 'hello', data: 'hello', type: 'comment' },
       { raw: '");', data: '");', type: 'text' } ] } ]

Expected output:

[ { raw: 'script',
    data: 'script',
    type: 'script',
    name: 'script',
    children: 
     [ { raw: 'document.write("<!--hello-->");',
         data: 'document.write("<!--hello-->");',
         type: 'text' } ] } ]

papandreou avatar Apr 24 '12 13:04 papandreou

If you have a patch or pull request I will apply it to the 1.x branch, otherwise I am focusing efforts on getting 2.x tested and released.

tautologistics avatar Apr 26 '12 12:04 tautologistics