Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: attributes seperated with non-breakable space not parsed properly #413

Closed
chimurai opened this issue Feb 26, 2020 · 2 comments
Closed

Comments

@chimurai
Copy link

A non-breakable space between attributes results in incorrect parsing:

<h1 tests foo="bar">My First Heading</h1>
         ^--- non-breakable space

current ast:

{
  "type": "tag",
  "name": "h1",
  "attribs": {
    "tests foo": "bar"
  }
}

expected ast:

{
  "type": "tag",
  "name": "h1",
  "attribs": {
    "tests": "",
    "foo": "bar"
  }
}

View AST online:
https://astexplorer.net/#/gist/d13142c629efe70f7b96ca3ff980890e/18c8e5c240f93bf3a45d0685bf399f398bfdfd33

non breakable space: https://en.wikipedia.org/wiki/Non-breaking_space
mac: alt + shift + space

Link to online AST with htmlparser2:

https://astexplorer.net/#/gist/d13142c629efe70f7b96ca3ff980890e/cf631a5987db518147e5d31687499701060db8d0

This issue is also present in the posthtml-parser, which uses htmlparser2:
posthtml/posthtml-parser#40

@fb55
Copy link
Owner

fb55 commented Mar 4, 2020

This seems in-line with what browsers do.

@fb55 fb55 closed this as completed Mar 4, 2020
@chimurai
Copy link
Author

chimurai commented Mar 4, 2020

Thanks for looking into to it.

Looks like non-breaking space (U+00A0) can be part of the attribute name.

https://html.spec.whatwg.org/multipage/syntax.html#attributes-2

Attributes have a name and a value. Attribute names must consist of one or more characters other than controls, U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=), and noncharacters. In the HTML syntax, attribute names, even those for foreign elements, may be written with any mix of ASCII lower and ASCII upper alphas.

CSS behaves similarly:
https://jsfiddle.net/dzpqvx6r/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants