dperini / nwsapi

Fast CSS Selectors API Engine
MIT License
105 stars 37 forks source link

Id starting with digit throws SyntaxError: '...' is not a valid selector #66

Closed avenezia closed 1 year ago

avenezia commented 2 years ago

Hi,

when using an id which starts with a digit, nwsapi throws a "SyntaxError: '...' is not a valid selector", I guess because of the identifier regexp.

As mentioned in https://www.w3.org/TR/html4/types.html#type-id, ID and NAME tokens must begin with a letter ([A-Za-z]). But, as described in https://html.spec.whatwg.org/multipage/dom.html#global-attributes:the-id-attribute-2, this constraint is not in place anymore for html5. For this reason, could nwsapi be updated to take this into account maybe through an option?

Thanks, Alessandro

dperini commented 2 years ago

@avenezia since the ID attribute can now start with a digit or an underscore, or consist of just digits or of just punctuation (as for the new HTML specifications for which you provided a link), nothing prevents an update of the "identifier" regular expression. So yes, we can do that if no other reason is preventing the hoisting of these restrictions. It will be just a matter of time and testing to ensure consistency with existing usage. Thank you for the heads-up, contribution are always welcome.

dperini commented 1 year ago

@avenezia I have added the configuration flag NONDIGITS to make digit at the start of ids and classes being recognized as valid as for the latest HTML5 specifications.

As soon as jsdom/wpt confirms they accept this behavior I will make this the default. Currently WPT tests have not been changed yet this is the reason I kept the old behavior.

Thank you .

dperini commented 1 year ago

Fixed and ready to go in next release.

avenezia commented 1 year ago

That's great, thank you @dperini!