isaacs / sax-js

A sax style parser for JS
Other
1.1k stars 325 forks source link

Unhandled espaced quote on attributes #217

Open llafuente opened 7 years ago

llafuente commented 7 years ago

Hi,

<x value="evil is \"inside"></x> is not parsed properly (to my HTML eyes at least ^^)

I expect to have an attribute with value with value evil is "inside Instead sax found two attributes, also report some erorrs, due not handling \"

TEST

const sax = require("../sax/sax.js");
const parser = sax.parser(true, {
  lowercase: true,
  //strictEntities : true
});
parser.onerror = console.log.bind(console);
parser.onopentag = console.log.bind(console);
parser.onclosetag = console.log.bind(console);
parser.onend = console.log.bind(console);

parser.write(`<x value="evil is \"inside"></x>`).close();
output:
Line: 0
Column: 20
Char: i
    at error (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:667:10)
    at strictFail (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:693:7)
    at Object.write (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:1411:13)
    at Object.<anonymous> (C:\Users\xe64758\Documents\GitHub\html-formatter\test\test.js:464:8)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
Error: Invalid attribute name
Line: 0
Column: 26
Char: "
    at error (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:667:10)
    at strictFail (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:693:7)
    at Object.write (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:1346:13)
    at Object.<anonymous> (C:\Users\xe64758\Documents\GitHub\html-formatter\test\test.js:464:8)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
Error: Attribute without value
Line: 0
Column: 27
Char: >
    at error (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:667:10)
    at strictFail (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:693:7)
    at Object.write (C:\Users\xe64758\Documents\GitHub\html-formatter\sax\sax.js:1337:13)
    at Object.<anonymous> (C:\Users\xe64758\Documents\GitHub\html-formatter\test\test.js:464:8)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
{ name: 'x',
  attributes: { value: 'evil is ', inside: 'inside' },
  isSelfClosing: false }
x
michaelnisi commented 7 years ago

Ouch! That‘s bad, not to say evil. Is this with attributes or in general? <x>"evil is \"inside"</x>.

brianmjerome commented 6 years ago

I'm running into this issue trying to parse a JSON string value: ...<data>{"USER":[{"NAME":"Bar, Foo<span class=\"icon\">User</span>"}]}</data>... I get the error pointing to the \".