fix(unhead): parse HTML attribute values without backslash escaping#774
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR updates the HTML attribute parser to stop treating backslashes as escape characters in quoted values. A quote character now unconditionally terminates a quoted attribute value, matching browser behavior. A clarifying comment and three test cases validate the updated parsing logic for backslashes and mixed attribute syntax. ChangesAttribute Parser Backslash Handling
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle Size Analysis
|
🔗 Linked issue
No linked issue. Found during a security sweep of
packages/unhead/src.❓ Type of change
📚 Description
parseAttributes(used bytransformHtmlTemplate) treated\as an escape character inside quoted attribute values. HTML has no backslash escaping there, so a trailing backslash swallowed the closing quote and diverged from both the browser and the tag-boundary scanner in the same file:href="C:\"parsedhrefasC:\"(browser:C:\)content="a\" name="description"parsedcontentasa\" name=plus a junk attribute (browser:content=a\,name=description)Output is re-escaped on render, so this is a parsing-correctness issue, not an injection. Dropped the backslash branch in the
QUOTED_VALUEstate so the quote char always terminates the value.BACKSLASH_CHARis still used byfindClosingTagfor quote-aware script/style scanning. Addedtest/unit/parser/parseAttributes.test.tscovering the trailing-backslash cases plus basic quoted, unquoted, and boolean attributes.