-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: strip // comments from unknown at-rule preludes
#4544
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
dchaudhari7177
wants to merge
2
commits into
less:master
Choose a base branch
from
dchaudhari7177:fix/3527-supports-line-comments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...es/test-data/tests-unit/at-rules-unknown-line-comments/at-rules-unknown-line-comments.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| @supports selector( | ||
| :focus-visible ) { | ||
| a { | ||
| color: red; | ||
| } | ||
| } | ||
| @supports (display: grid) { | ||
| .grid { | ||
| display: grid; | ||
| } | ||
| } | ||
| @supports (background: url(http://example.com/a.png)) { | ||
| .absolute-url { | ||
| color: blue; | ||
| } | ||
| } | ||
| @document url-prefix(http://example.com/) { | ||
| .doc { | ||
| color: green; | ||
| } | ||
| } | ||
| @supports (background: url(//cdn.example.com/x.png)) { | ||
| .protocol-relative { | ||
| background: url(//cdn.example.com/x.png); | ||
| } | ||
| } | ||
| @supports (a: b) /* keep me */ { | ||
| .block-comment { | ||
| color: teal; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...s/test-data/tests-unit/at-rules-unknown-line-comments/at-rules-unknown-line-comments.less
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // A `//` comment inside an unknown at-rule prelude is scanned as raw text by | ||
| // $parseUntil, so it used to survive into the CSS and swallow the rest of the | ||
| // line with it. | ||
|
|
||
| @supports selector( | ||
| :focus-visible // a line comment | ||
| ) { | ||
| a { | ||
| color: red; | ||
| } | ||
| } | ||
|
|
||
| @supports (display: grid) // trailing comment | ||
| { | ||
| .grid { | ||
| display: grid; | ||
| } | ||
| } | ||
|
|
||
| // A `//` that is not preceded by whitespace is not a comment: it is part of a | ||
| // URL. These must be left alone. | ||
| @supports (background: url(http://example.com/a.png)) { | ||
| .absolute-url { | ||
| color: blue; | ||
| } | ||
| } | ||
|
|
||
| @document url-prefix(http://example.com/) { | ||
| .doc { | ||
| color: green; | ||
| } | ||
| } | ||
|
|
||
| @supports (background: url(//cdn.example.com/x.png)) { | ||
| .protocol-relative { | ||
| background: url(//cdn.example.com/x.png); | ||
| } | ||
| } | ||
|
|
||
| // Block comments are valid CSS and stay. | ||
| @supports (a: b) /* keep me */ { | ||
| .block-comment { | ||
| color: teal; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preceding-whitespace check cannot reliably distinguish comments from URLs. For example, a valid protocol-relative URL with whitespace after
url(, such as@supports (background: url( //cdn.example/x)), meets this condition, so the scanner removes the URL and the rest of the line, including its closing delimiters. Conversely, a Less comment directly adjacent to prelude content, such as@supports (display: grid)// comment, fails the condition and remains in the generated CSS. Unknown at-rule preludes are therefore corrupted for both realistic forms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both cases were real, thanks. Fixed in 3c7bf86. The whitespace test is gone. A
//is now left alone only insideurl(,url-prefix(ordomain((the value parser also stops absorbing comments there), or right after a:(a scheme).url( //cdn.example.com/y.png)keeps its address, and(display: flex)// commentis stripped. Both are in the fixture now, and the previous parser fails them.grunt test:nodepasses.