syntax-tree / hast

Hypertext Abstract Syntax Tree format

Home Page:https://unifiedjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect parsing of the `sizes` attribute

andrewburgess opened this issue · comments

Related to: wooorm/property-information#14

The sizes attribute is parsed differently depending on whether it is part of a link element or an img element. The pull request referenced above would change sizes to be commaOrSpaceSeparated which would be parsed here as splitting on commas first, and then on spaces after rejoining the array into a space separated string.

For the element:

<img
    sizes="(max-width: 600px) 100vw, 800px"
    src="example.png"
    srcset="example.png 400px, example.png 800px"
/>

the sizes attribute would be parsed and turned into the array

["(max-width:", "600px)", "100vw", "800px"]

instead of the expected

["(max-width: 600px) 100vw", "800px"]

I was thinking of changing the above referenced line to be:

result = result.indexOf(',') >= 0 ? commas(result) : spaces(result)

but that breaks existing tests since they seem to be handling the case of "comma AND space separated".

I'm also not sure if that change would cover all cases since it seems that the sizes grammar would allow for a solo <media-condition> <source-size-value> which shouldn't be split up