Re: [csswg-drafts] [css-syntax-3] `url(` followed by comment(s) (#10125)

The change from the special url token to a standard function token was resolved on several years ago, if and only if the first substantive thing inside the parentheses is a string. Otherwise it continues to be parsed as the special-case url-token. (This allows us to handle additional arguments, which otherwise would require even more special parsing to keep in the url token syntax.)

Refreshing myself on the actual text, it appears that impls *are* in fact following the spec. After you see the `url(`, you scan forward until you stop seeing whitespace; if the next character is a `"` or `'`, you go ahead and emit the `url(` as a function token and parse as normal (leaving some whitespace behind, if needed, to ensure a ws token is emitted); otherwise you parse as a url token.

This means that, per spec, seeing the `/` that would normally start a comment actually triggers the "parse as a url token" behavior. And then in that algorithm, seeing a `"` is a parse error (it normally means you'd written something like `url(foo"bar")`, which is a mistake).

So yeah, impls match the spec. And I think the spec needs to stay as it is; comments are otherwise ambiguous syntax. In theory I could add more scan-ahead to see if the comment is closed and (after potentially more ws and comments) then I hit a quote character, but it would impose a little more parsing cost on impls to support a syntax that wasn't previous allowed anyway.

I no longer have an old impl around to test, but I *suspect* that `url(/**/"foo")` was probably always invalid, so the current behavior is consistent with that, too.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10125#issuecomment-2016943026 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 24 March 2024 21:06:07 UTC