Skip to content

8383783: MediaQueryParser should reject query lists without comma separator#2162

Closed
mstr2 wants to merge 2 commits into
openjdk:masterfrom
mstr2:fixes/query-lists-comma
Closed

8383783: MediaQueryParser should reject query lists without comma separator#2162
mstr2 wants to merge 2 commits into
openjdk:masterfrom
mstr2:fixes/query-lists-comma

Conversation

@mstr2

@mstr2 mstr2 commented May 3, 2026

Copy link
Copy Markdown
Collaborator

MediaQueryParser currently parses query lists without a comma separator:

    @media (prefers-color-scheme: dark)
           (prefers-reduced-motion: reduce) {
        .foo { bar: baz; }
    }

The correct grammar requires commas between queries.



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8383783: MediaQueryParser should reject query lists without comma separator (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/2162/head:pull/2162
$ git checkout pull/2162

Update a local copy of the PR:
$ git checkout pull/2162
$ git pull https://git.openjdk.org/jfx.git pull/2162/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2162

View PR using the GUI difftool:
$ git pr show -t 2162

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/2162.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented May 3, 2026

Copy link
Copy Markdown

👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@mstr2 mstr2 changed the title MediaQueryParser should reject query lists without comma separator 8383783: MediaQueryParser should reject query lists without comma separator May 3, 2026
@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

@mstr2 This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8383783: MediaQueryParser should reject query lists without comma separator

Reviewed-by: angorya, mhanl

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 15 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@mstr2 mstr2 marked this pull request as ready for review May 3, 2026 07:13
@openjdk openjdk Bot added the rfr Ready for review label May 3, 2026
@openjdk

openjdk Bot commented May 3, 2026

Copy link
Copy Markdown

The total number of required reviews for this PR has been set to 2 based on the presence of this label: rfr. This can be overridden with the /reviewers command.

@mlbridge

mlbridge Bot commented May 3, 2026

Copy link
Copy Markdown

Webrevs

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preliminary review, I'd like to test it a bit more.

errorHandler.accept(stream.consume(), "Expected COMMA");

while (stream.consumeIf(NOT_COMMA) != null) {
// Skip forward to the next comma and replace the previous query with a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the case that parserRecoversFromMissingCommaBetweenMediaQueries() exercise?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We only expect another media condition after a comma, and if there was no comma, the if (!expectMediaCondition) failure path is taken.

errorHandler.accept(stream.current(), "Unexpected token");
Token comma = stream.consume();
if (expectMediaCondition || expressions.isEmpty()) {
errorHandler.accept(comma, "Unexpected token");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to test this failure path, and also in L134 for completeness sake?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes sense. I've added tests for all failure paths where the media query list is malformed. Now we consistently apply the rule that a malformed query evaluates to false, but doesn't stop the parser.

@andy-goryachev-oracle

Copy link
Copy Markdown
Contributor

should this malformed css fail? (it does not)

@media
    {
        .button { -fx-background-color: red; }
    }

@mstr2

mstr2 commented May 21, 2026

Copy link
Copy Markdown
Collaborator Author

should this malformed css fail? (it does not)

@media
    {
        .button { -fx-background-color: red; }
    }

This should work and correspond to a true query. See MediaQueryList L74:

    /**
     * Evaluates whether any of the media queries is {@code true}.
     *
     * @param context the evaluation context
     * @return {@code true} if any of the media queries is {@code true} or if the list is empty,
     *         {@code false} otherwise
     */
    public boolean evaluate(MediaQueryContext context)

See also here:

An empty media query list evaluates to true.

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you for explanations and adding the tests.

@Maran23

Maran23 commented May 22, 2026

Copy link
Copy Markdown
Member

I can be the second reviewer.

@Maran23 Maran23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I also checked the test coverage. New code is very well covered by all the tests.
Image

@openjdk openjdk Bot added the ready Ready to be integrated label May 25, 2026
@mstr2

mstr2 commented May 25, 2026

Copy link
Copy Markdown
Collaborator Author

/integrate

@openjdk

openjdk Bot commented May 25, 2026

Copy link
Copy Markdown

Going to push as commit 6981fb4.
Since your change was applied there have been 15 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label May 25, 2026
@openjdk openjdk Bot closed this May 25, 2026
@openjdk openjdk Bot removed ready Ready to be integrated rfr Ready for review labels May 25, 2026
@openjdk

openjdk Bot commented May 25, 2026

Copy link
Copy Markdown

@mstr2 Pushed as commit 6981fb4.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants