Skip to content

fix(preset-attributify): prevent backtick match from spanning lines in elementRE - #5286

Merged
zyyv merged 2 commits into
unocss:mainfrom
FrancoKaddour:fix/attributify-backtick-multiline
Aug 31, 2026
Merged

zyyv merged 2 commits into
unocss:mainfrom
FrancoKaddour:fix/attributify-backtick-multiline

Conversation

@FrancoKaddour

Copy link
Copy Markdown
Contributor

Description

Closes #4818. In presetAttributify, an attribute like c="red" was not extracted when a nearby line contained a backtick (e.g. a JSX id={ `${a}` }) together with a stray quote. The backtick alternative in elementRE matched across newlines, so an unclosed backtick on one line jumped to a backtick on a later line, swallowing everything in between — including the c="red" attribute.

Fix

Restrict the backtick alternative in elementRE to a single line by adding \n to its negated class. A template literal inside an element's opening tag never legitimately spans lines (real JSX cases like id={ `${a}` } stay on one line), so this scopes the match without affecting valid usage. The single/double-quote and {} alternatives are left untouched, preserving existing multiline attribute support (the m='...' and multiline v-for="..." test cases still pass).

Testing

Added a regression test asserting the extractor recovers [c~="red"] from the exact reproduction. Verified it fails on main and passes with the fix; the full preset-attributify suite (17 tests) stays green.

Thanks to @alpacaonthehill for the clear minimal reproduction.

…n elementRE

An attribute like c="red" was not extracted when a nearby line contained a
backtick (e.g. a JSX template literal) together with a stray quote. The
backtick alternative in elementRE matched across newlines, so an unclosed
backtick on one line jumped to a backtick on a later line, swallowing the
attributes in between.

Restrict the backtick alternative to a single line. Template literals inside an
element's opening tag never legitimately span lines, so this scopes the match
without affecting valid usage; the quote and brace alternatives are untouched,
preserving multiline attribute support.

Closes unocss#4818
@netlify

netlify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 79d25b5
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/6a94e335014f8b00086c4cc2
😎 Deploy Preview https://deploy-preview-5286--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Aug 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 79d25b5

@zyyv
zyyv added this pull request to the merge queue Aug 31, 2026
Merged via the queue into unocss:main with commit e4a19c3 Aug 31, 2026
11 checks passed
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.

Class is not extracted from a line of code if surrounded by certain combinations of template literals

2 participants