rayd / html-parse-stringify2

Parses well-formed HTML (meaning all tags closed) into an AST and back. quickly.
21 stars 11 forks source link

Fails for boolean attributes #13

Closed des-des closed 7 years ago

des-des commented 7 years ago

@rayd I am getting a problem in a dependency (snabbdom-virtualize). I think it is being caused by the way this lib handles boolean attributes.

like

<script async type='text/javascript' ...

when this gets parsed we end up with an attribute name text/javascript which causes an error when I update the dom.

des-des commented 7 years ago

Here is the failing test case


    tag = '<input checked name="sad" type="checkbox">';

    t.deepEqual(parseTag(tag), {
        type: 'tag',
        attrs: {
            type: 'checkbox',
            checked: 'checked', // This conforms to spec for boolean attributes
            name: 'sad'
        },
        name: 'input',
        voidElement: false,
        children: []
    });

With output

 expected:
      { attrs: { checked: 'checked', name: 'sad', type: 'checkbox' }, children: [], name: 'input', type: 'tag', voidElement: false }
    actual:
      { attrs: { '"sad"': 'type', checked: 'name' }, children: [], name: 'input', type: 'tag', voidElement: true }
rayd commented 7 years ago

Fixed in 2.0.1 with #14