Repository navigation
Keep a declaration without a ; at the end of the CSS input
#20655
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - Keep a declaration without a `;` at the end of the CSS input (e.g. `color: red`) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -597,6 +597,31 @@ export function parse(input: string, opts?: ParseOptions) { | |
| ast.push(node) | ||
| } | ||
|
|
||
| // If we have any other leftover `buffer` then it can be a declaration that | ||
| // is not terminated with a semicolon at the end of the input. Unbalanced | ||
| // brackets (e.g. `color: rgb(1, 2`) mean that the declaration is incomplete. | ||
| // | ||
| // E.g.: | ||
| // | ||
| // ```css | ||
| // color: red | ||
| // ``` | ||
| else if (buffer.length > 0 && closingBracketStack.length === 0) { | ||
| let declaration = parseDeclaration(buffer) | ||
|
Comment on lines
+609
to
+610
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle a trailing backslash before emitting the declaration. For
|
||
| if (declaration) { | ||
| if (source) { | ||
| declaration.src = [source, bufferStart, input.length] | ||
| declaration.dst = [source, bufferStart, input.length] | ||
| } | ||
|
|
||
| if (parent) { | ||
| parent.nodes.push(declaration) | ||
| } else { | ||
| ast.push(declaration) | ||
| } | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| // When we are done parsing then everything should be balanced. If we still | ||
| // have a leftover `parent`, then it means that we have an unterminated block. | ||
| if (closingBracketStack.length > 0 && parent) { | ||
|
|
||
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.
Script executed:
Repository: tailwindlabs/tailwindcss
Length of output: 41913
Script executed:
Repository: tailwindlabs/tailwindcss
Length of output: 28716
Reject EOF declarations with an unclosed square bracket.
parseDeclarationacceptsgrid-template-columns: [sidebarat EOF, andtoCssemits the value unchanged.substituteAtImportsreplaces imports with AST nodes; it does not consume sibling nodes itself. However, the serialized stylesheet contains an unclosed[, so a downstream CSS parser can consume the following semicolon, closing brace, and later rules as part of that unfinished block.Add a string-aware square-bracket check. Brackets inside quoted strings must not count, so
content: "["remains valid.Suggested fix
Implement
hasUnclosedSquareBracketwith escape- and quote-aware scanning, and add tests for bothgrid-template-columns: [sidebarandcontent: "[".