Skip to content

[css-syntax-3] Consume an ident-like token algorithm differs for function tokens that start with url #8280

Description

@romainmenke

https://www.w3.org/TR/css-syntax-3/#consume-ident-like-token

  1. If string’s value is an ASCII case-insensitive match for "url", and the next input code point is U+0028 LEFT PARENTHESIS ((), consume it
  2. While the next two input code points are whitespace, consume the next input code point.
  3. If the next one or two input code points are U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), or whitespace followed by U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('), then create a <function-token> with its value set to string and return it.

This algorithm indicates that whitespace characters are consumed and "attributed" to the function token.

For example two spaces before "foo" :

url(  "foo")

Following this algorithm it tokenizes as :

['function-token', 'url( ', 0, 4, { value: 'url' }],
['whitespace-token', ' ', 5, 5, undefined],
['string-token', '"foo"', 6, 10, { value: 'foo' }],
[')-token', ')', 11, 11, undefined],
['EOF-token', '', -1, -1, undefined],

While any other function name tokenizes as :

['function-token', 'not-url(', 0, 7, { value: 'not-url' }],
['whitespace-token', '  ', 8, 9, undefined],
['string-token', '"foo"', 10, 14, { value: 'foo' }],
[')-token', ')', 15, 15, undefined],
['EOF-token', '', -1, -1, undefined],

The raw values of the function tokens are :

  • 'url( ' (notice the trailing space)
  • 'not-url('

The raw values of the whitespace tokens are :

  • ' '
  • ' '

Sorry for the technical notation, when I tried to write it differently it became more ambiguous


First of all I am unsure if I read the specification correctly.
I don't know if I am tokenizing these correctly or if I have a bug.

I don't think it affects parsing because the meaningful values are not affected by consuming whitespace in this way.

This might be relevant in developer tooling where it is important to tokenize and serialize without mutations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-syntax-3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions