Skip to content
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

Regex Endless Loop stalling build when using attributify mode and < char #2067

Closed
MiniDigger opened this issue Jan 10, 2023 · 3 comments · Fixed by #2134
Closed

Regex Endless Loop stalling build when using attributify mode and < char #2067

MiniDigger opened this issue Jan 10, 2023 · 3 comments · Fixed by #2134

Comments

@MiniDigger
Copy link

This is a really weird issue and took me waaaaaaaaaayyyy to long to figure out.
I converted a project from windi to unocss today and everything worked great, locally, but my build on github actions stalled. upon verification locally, I could reproduce that.
now followed a few hours of digging and I have pinned the issue down: using < in classes in certain combinations causes a regex catastrophic backtracking.
I managed to debug my way thru stuff and eventually managed to create this minimal repro: https://stackblitz.com/edit/github-y3a65o?file=app.vue
notice how stuff seems to work in pnpm run dev, but pnpm run build just freezes. Removing the < in line 9 fixes the freeze. removing the space + d behind color-red also fixes the freeze.
The issue is this regex: https://github.com/unocss/unocss/blob/main/packages/preset-attributify/src/extractor.ts#L11
If you take that regex and the code that unocss scans for that component into regex101, it will complain about catastrophic backtracking: https://regex101.com/r/Ib1eKA/1
(I obtained the code by console logging the code var here https://github.com/unocss/unocss/blob/main/packages/preset-attributify/src/extractor.ts#L24, before the regex match)
Remove the < and it works, remove the space after the color-red and it works too (as in no match, but no endless loop either).

thats pretty much all find I found out tonight, hopefully that is somewhat helpful to hunt this one down, I tries to understand the regex, but its 2am now and I didn't come far, lol

ps, I know < should be lt in unocss, after talking about the solution to this issue with friends, but I still think this is a valid issue, < could be located elsewhere in the code and theoretically trigger this I think.

@zyyv
Copy link
Member

zyyv commented Jan 11, 2023

@MiniDigger
Copy link
Author

yes, I was made aware, I said in the last sentence, but its still a valid issue

@chu121su12
Copy link
Collaborator

Smaller subset of string that's causing this:

https://regex101.com/r/48y4HT/1

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 a pull request may close this issue.

3 participants