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

Version 4.1.2 and 4.1.3 breaks collapse data-target, if id starts with a number #27018

Closed
morganwillcock opened this issue Aug 3, 2018 · 4 comments

Comments

@morganwillcock
Copy link

It seems that versions past 4.1.1 have stopped my collapsed elements from being identified. The id numbers are generated through templating and are actually md5 hashes, this was previously fine but now these don't work when the id starts with a number.

i.e.
data-target="#98d777f385d3dfec8815d20f7496026dc" has stopped working
data-target="#9" doesn't work
data-target="#a98d777f385d3dfec8815d20f7496026dc" is fine
data-target="#a9" is fine

Downgrading to 4.1.1 makes everything work again.

Operating system: Debian 9 x64
Browser and version: Firefox 52.9 (ESR)
Test case: https://jsbin.com/mezetokase/edit?html,output

@razh
Copy link
Contributor

razh commented Aug 3, 2018

See: #26968 (comment)

Note: Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in HTML 5, an ID should start with a letter for compatibility.

From https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

document.querySelector requires that id values start with a letter.

@morganwillcock
Copy link
Author

Hmm, there seems to be some confusion with the spec:
https://www.w3.org/TR/html5/dom.html#element-attrdef-global-id

There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.

...but thanks. That does clear it up.

@razh
Copy link
Contributor

razh commented Aug 3, 2018

@morganwillcock It technically does work... but you have to escape it in a very awkward fashion.

For example:

<input id="98d777f385d3dfec8815d20f7496026dc">

It would be:

document.querySelector('#\\39 8d777f385d3dfec8815d20f7496026dc');

See: http://mathiasbynens.be/notes/css-escapes

Leading digits

If the first character of an identifier is numeric, you’ll need to escape it based on its Unicode code point. For example, the code point for the character 1 is U+0031, so you would escape it as \000031 or \31 .

Basically, to escape any numeric character, just prefix it with \3 and append a space character ( ). Yay Unicode!

@morganwillcock
Copy link
Author

Ah right. Thank you for the link!

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