Coder Social home page Coder Social logo

Comments (2)

paquettg avatar paquettg commented on July 17, 2024

I agree that we should handle this. I am more curious in knowing how you think we should handle this.

I have a few ideas but I am not fully aware of how browsers do this. If you have any insight into this or any ideas please let me know.

thanks

from php-html-parser.

dirtside avatar dirtside commented on July 17, 2024

Ultimately it comes down to detecting the > that ends the start tag, which can be tricky if there's multiple > inside other attributes in the tag, or an uneven number of " marks spread across one or more attributes. I assume browsers use some complicated heuristics, but messing around with various befunged attributes in Firefox, it looks like it treats the first > that's not inside an attribute (that is, not between a matching pair of " marks) as the end of the open tag. Everything after that (until a <) is considered part of the body of the element.

So there'd be two main (non-nominal) cases: an attribute with an extra pair of unescaped " inside of it (e.g. <a title="This "is" an attribute">), and an attribute with one extra " inside it (e.g. <a title="This "is an attribute">). The former is obviously easier; the latter could be treated as having one attribute called title with value This, and three other attributes named is, an, and attribute, each with empty values (the " immediately after attribute would be discarded as an invalid token since you can't have a double quote after an attribute name, there has to be an = first). The > is thus not inside an attribute, from the parser's POV, and ends the tag.

Another edge case is something like this: <span title=">something</span>. Firefox discards the entire thing as unparseable.

Presumably the corresponding logic can be found (somewhere) in the vast Firefox (Gecko?) and Chrome (Chromium) codebases.

from php-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.