tXml icon indicating copy to clipboard operation
tXml copied to clipboard

Properly parse unquoted attributes (pleasešŸ™?)

Open piccojs opened this issue 2 years ago ā€¢ 3 comments

Whenever I parse this string:

<p type=bold>hello mom!</p>

I get unexpected results:

{
  tagName:"p",
  attributes:{
    type:null,
    bold:null
  },
  children:["hello mom!"]
}

I know this is an xml parser but wouldn't it just make sense to generate:

{
  tagName:"p",
  attributes:{
    type:"bold"
  },
  children:["hello mom!"]
}

Please consider adding such type parsing in the next bug fix, I love your library! šŸ„°šŸ„°

piccojs avatar Mar 21 '22 20:03 piccojs

thanks, this really is a bug. I can confirm it, in a quick test. it need to be fixed in the parseNode method between line 200 and 220: https://github.com/TobiasNickel/tXml/blob/0dddcb277d206fb319f29da73932efecbe300137/tXml.js#L199-L224

To be honest, even I find the code at line 204 a bit difficult to read, But with spending some time we should be able to figure this out.

TobiasNickel avatar Mar 22 '22 05:03 TobiasNickel

but that one is invalid xml right? there's suppose to be quote (single or double) around bold?

<p type="bold">hello mom!</p>

tuananh avatar Oct 13 '22 04:10 tuananh

right, but still many html pages do not have quotes. the values then can not contain any space.

TobiasNickel avatar Oct 26 '22 06:10 TobiasNickel