Coder Social home page Coder Social logo

Comments (6)

oalders avatar oalders commented on August 23, 2024

Thanks for the test case @simbabque!

from html-parser.

oalders avatar oalders commented on August 23, 2024

It might be helpful to add this as a TODO test as well.

from html-parser.

andyjack avatar andyjack commented on August 23, 2024

I've also run into this issue a couple of times - digging deeper into HTML::Parser reveals that setting the value to the name is intentional! There is an option to control what value is "parsed" when an attribute has no value.

; perl -MHTML::TokeParser -MDDP -lE 'my $p = HTML::TokeParser->new( doc => \qq{<input type="text" name="abc123" value>}, boolean_attribute_value=>"no value!")->get_tag->[1]; p $p'
{
    name    "abc123",
    type    "text",
    value   "no value!"
}

The current design of "return the name" doesn't seem sensible to me - having the default setting for the option be undef or q{} would align the module with the HTML spec, but that would probably affect downstream code.

Here's where setting the value to the name happens in the C code.

from html-parser.

wolfsage avatar wolfsage commented on August 23, 2024

This part of the parser specifically mentions 'boolean' - I believe it's referring to this:

https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

and

Example:

Here is an example of a checkbox that is checked and disabled. The checked and disabled attributes are the boolean attributes.

<label><input type=checkbox checked name=cheese disabled> Cheese</label>

This could be equivalently written as this:

<label><input type=checkbox checked=checked name=cheese disabled=disabled> Cheese</label>

I think what this means is that HTML::Parser needs to be aware of the types of the attributes its parsing, which makes it seem like the fix won't be so easy?

from html-parser.

oalders avatar oalders commented on August 23, 2024

This blog post states that there are 25 attributes which are boolean. https://meiert.com/en/blog/boolean-attributes-of-html/

If that's correct, they could be special-cased, but from my quick digging I didn't find a definitive list elsewhere, so I'm not confident in this yet.

from html-parser.

andyjack avatar andyjack commented on August 23, 2024

Thanks for the info about boolean attributes - the "return the name" behavior makes sense now.

Does a user of HTML::Parser care about differentiating between <... checked ...>, <... checked="checked" ...> and <... checked="" ...> being parsed? This might affect the fix for the issue.

from html-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.