New issue
Advanced search Search tips

Issue 808828 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

querySelector syntax error for digit only id attribute

Reported by studdu...@gmail.com, Feb 3 2018

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36

Steps to reproduce the problem:
1. Construct an HTML 5 document w/ an element whose id attribute consists solely of numbers (e.g., 1234)
2. Open dev tools and navigate to the page/document
3. Select the console tab
4. Execute the following Javascript: $$('#1234')

What is the expected behavior?
It should have returned the element.

What went wrong?
SyntaxError: '#1234' is not a valid selector

Did this work before? N/A 

Chrome version: 56.0.2924.87  Channel: stable
OS Version: 
Flash Version: Shockwave Flash 28.0 r0

The problem is not limited to devtools. It happens in Javascript on the page. Devtools is just the easiest way to reproduce it.

So the bug is this. According to the HTML5 spec, the only restrictions on the id attribute are that it must be unique and it must contain at least one character. So the selector, "#1234", has no syntax errors but Firefox says otherwise. Additionally, calling document.getElementById('1234') returns the Element w/o issue.
 

Comment 1 by woxxom@gmail.com, Feb 3 2018

This is working as intended.
The correct specification here is not HTML5, but CSS.
https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier

  > cannot start with a digit
  > can contain escaped characters and any ISO 10646 character as a numeric code

In CSS the number-only id selector is invalid so it should be escaped e.g. $$("#\\31 234")
Labels: Needs-Milestone
#1 is correct. You can use attribute selector


// note quotes surrounding value portion of attribute selector
document.querySelector("[id='1234']")

See Is 111 a valid HTML id attribute or are document.querySelector() and document.querySelectorAll() correctly throwing syntax errors?
 https://stackoverflow.com/questions/45519853/is-111-a-valid-html-id-attribute-or-are-document-queryselector-and-document-qu
This is not a bug.

The expected behaviour is for a DOMException error to be thrown, as `#1234` is not a valid CSS selector. 

Comment 5 by tkent@chromium.org, Feb 5 2018

Components: -Blink Blink>CSS Blink>DOM
Status: WontFix (was: Unconfirmed)

Sign in to add a comment