Skip to content

[css-syntax-3] New parsing algorithms do not handle } tokens correctly in style attributes #11113

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

Open
AtkinsSJ opened this issue Oct 30, 2024 · 1 comment

Comments

@AtkinsSJ
Copy link
Contributor

This WPT test checks that } tokens inside a style attribute are ignored and skipped over. Specifically, these two cases from it fail when following the new parsing algorithms:

<p style="};background:limegreen">This line should have a green background.
<p style="background:red;};background:limegreen">This line should have a green background.

The previous version of the spec says:

"Parse a list of declarations" is for the contents of a style attribute, which parses text into the contents of a single style rule.

That then calls "consume a list of declarations", which when it sees a } token, discards it and the remaining tokens up until the next ;, and then continues parsing the next declaration.

The current draft spec with the new parsing algorithms says:

"Parse a block’s contents" is intended for parsing the contents of any block in CSS (including things like the style attribute), and APIs such as the CSSStyleDeclaration cssText attribute.

However, this now calls "consume a block’s contents" which when it sees a }, immediately exits out and returns the current list of declarations. This makes it fail the above test cases, because declarations after a } are completely ignored.

A Ladybird contributor has proposed a change which seems to restore the previous behaviour - basically by passing an is style attribute flag to "consume a block's contents" and using that to skip over declarations that contain a }.

@cdoublev
Copy link
Collaborator

cdoublev commented Nov 16, 2024

This resonated with me somewhat, so after some digging, it seems the related changes, listed below in chronological order, followed a comment from me:

In a nested context, } would indeed close the parent rule:

style {
  background:red;
}
/* trash */
; background:limegreen

An orphan } in the style attribute (or the input of CSSStyleDeclaration.cssText) can only be a typo that the new algos do not forgive.

cdoublev added a commit to cdoublev/css that referenced this issue Dec 19, 2024
Declarations are no longer hoisted or wrapped in a style rule.

Some problem remains...

1. @font-feature-values, @function, @page, can also have declarations
   interleaved with rules, but CSSNestedDeclarations is currently
   associated to style properties. (w3c/csswg-drafts#11272)

2. "}" should be ignored in a "style" attribute value (a declaration
   block) but the algorithm has been replaced with the same algorithm
   than for a block of rules and declarations. (w3c/csswg-drafts#11113)

3. The current text wants declarations interleaved by an invalid at-rule
   or an invalid (qualified) rule error to be separated, but the reason
   is not stated and no browser does this. (w3c/csswg-drafts#11271)

4. The current text clearly has some other minor typos and is not clear
   about whether rules and declaration, or only rules, should be
   returned. (w3c/csswg-drafts#11017)
cdoublev added a commit to cdoublev/css that referenced this issue Dec 19, 2024
Declarations are no longer hoisted or wrapped in a style rule.

Some problem remains...

1. @font-feature-values, @function, @page, can also have declarations
    interleaved with rules, but CSSNestedDeclarations is currently
    associated to style properties. (w3c/csswg-drafts#11272)

2. "}" should be ignored in a "style" attribute value (a declaration
    block) but the algorithm has been replaced with the same algorithm
    than for a block of rules and declarations. (w3c/csswg-drafts#11113)

3. The current text wants declarations interleaved by an invalid at-rule
    or an invalid (qualified) rule error to be separated, but the reason
    is not stated and no browser does this. (w3c/csswg-drafts#11271)

4. The current text clearly has some other minor typos and is not clear
    about whether rules and declaration, or only rules, should be
    returned. (w3c/csswg-drafts#11017)
cdoublev added a commit to cdoublev/css that referenced this issue Dec 19, 2024
Declarations are no longer hoisted or wrapped in a style rule.

Some problem remains...

1. @font-feature-values, @function, @page, can also have declarations
    interleaved with rules, but CSSNestedDeclarations is currently
    associated to style properties. (w3c/csswg-drafts#11272)

2. "}" should be ignored in a "style" attribute value (a declaration
    block) but the algorithm has been replaced with the same algorithm
    than for a block of rules and declarations. (w3c/csswg-drafts#11113)

3. The current text wants declarations interleaved by an invalid at-rule
    or an invalid (qualified) rule error to be separated, but the reason
    is not stated and no browser does this. (w3c/csswg-drafts#11271)

4. The current text clearly has some other minor typos and is not clear
    about whether rules and declaration, or only rules, should be
    returned. (w3c/csswg-drafts#11017)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants