Skip to content

fix: correct CSS error column numbers when <style> and content are on the same line#40490

Merged
banaag merged 2 commits intomainfrom
fix/css-error-column-same-line
Feb 27, 2026
Merged

fix: correct CSS error column numbers when <style> and content are on the same line#40490
banaag merged 2 commits intomainfrom
fix/css-error-column-same-line

Conversation

@Gregable
Copy link
Member

Fixes #40424

When <style amp-custom> and its CSS are on the same line (e.g. <style amp-custom>body{bad:css}</style>), CSS error column numbers point to the opening tag instead of the actual CSS content. This is because CdataMatcher passes the tag's position to the CSS tokenizer, and when everything's on one line the column offset is wrong. When they're on separate lines it doesn't matter since the newline resets the column.

The fix plumbs the text node's actual position (node->FirstChild()->LineColInHtmlSrc()) through to the CSS tokenizer, with a fallback to the existing behavior if unavailable. Same approach that's already used for JSON content error positions a few lines above.

Includes a test case with style tag and CSS on the same line.

… the same line

Plumb text node position through CdataMatcher to the CSS tokenizer so
that column numbers reflect the actual CSS content position, not the
opening tag position. Includes test case for same-line style+CSS.

Fixes #40424
@erwinmombay erwinmombay self-requested a review February 27, 2026 21:41
@erwinmombay
Copy link
Member

Good to see ya @Gregable :) . appreciate the contribution!

@erwinmombay erwinmombay requested a review from banaag February 27, 2026 21:42
Use the tag's line number (line_col_) but the content's column
(content_line_col) in MatchCss. This preserves correct line numbering
for multi-line stylesheets while fixing column offsets when CSS content
is on the same line as the <style> tag.

Also corrects the expected test output to match actual validator output.
Copy link
Contributor

@banaag banaag left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, Greg!

@banaag banaag merged commit db0a169 into main Feb 27, 2026
51 checks passed
@banaag banaag deleted the fix/css-error-column-same-line branch February 27, 2026 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validator returns incorrect column number when opening <style> is on the same line

3 participants