Skip to content

Fix infinite loop, specificity bug#257

Merged
sammycage merged 1 commit intosammycage:masterfrom
Randalphwa:first-of-type_bug
Jan 8, 2026
Merged

Fix infinite loop, specificity bug#257
sammycage merged 1 commit intosammycage:masterfrom
Randalphwa:first-of-type_bug

Conversation

@Randalphwa
Copy link
Contributor

This PR fixes a infinite loop when processing some SVG files. Fixing that loop also exposed an additional bug that caused the test svg fail to render incorrectly. The fix adds pseudo-class selectors to the specificity calculation with weight 0x100 (same as class and attribute selectors per CSS spec). Now rect:first-of-type has specificity 0x101 (element + pseudo-class) while plain rect has 0x1, so the first rectangle will correctly be red.

Test SVG

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 100">
  <style>
    rect:first-of-type { fill: red; }
    rect { fill: blue; }
  </style>
  <rect x="10" y="10" width="80" height="80"/>
  <rect x="110" y="10" width="80" height="80"/>
</svg>

@sammycage sammycage merged commit 2cdbfab into sammycage:master Jan 8, 2026
4 checks passed
@Randalphwa Randalphwa deleted the first-of-type_bug branch January 9, 2026 14:20
@sammycage
Copy link
Owner

Thank you <3

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.

2 participants