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

fix(vscode): attributify value starts with number #1811

Merged
merged 2 commits into from Oct 31, 2022

Conversation

zhmushan
Copy link
Contributor

The string to be tested here is the source code and does not need to be "escaped".

@zhmushan zhmushan requested a review from antfu as a code owner October 28, 2022 12:59
@netlify
Copy link

netlify bot commented Oct 28, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5d6b7a3
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/635d53b6fb45ac000993d6e4
😎 Deploy Preview https://deploy-preview-1811--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

test/pos.test.ts Outdated Show resolved Hide resolved
@@ -78,7 +78,7 @@ export function getMatchedPositions(code: string, matched: string[], hasVariantG

// attributify values
attributify.forEach(([, name, value]) => {
const regex = new RegExp(`(${e(name)}=)(['"])[^\\2]*?${e(value)}[^\\2]*?\\2`, 'g')
const regex = new RegExp(`(${name}=)(['"])[^\\2]*?${value}[^\\2]*?\\2`, 'g')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't e at least be replaced with escapeRegEx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at this function, but I'm sorry, I didn't figure out what it means. Can you explain it in detail?

Copy link
Member

Choose a reason for hiding this comment

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

I looked at this function, but I'm sorry, I didn't figure out what it means. Can you explain it in detail?

https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm sorry the function name was escapeRegExp. (see search)

export function escapeRegExp(string: string) {

This is usually done if you are using string from variable while constructing regex, similar to escaping string variable with e() or the like before using it in html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chu121su12 Thanks, you are right, I have replaced e() with escapeRegExp() and added tests.

@zhmushan zhmushan force-pushed the vscode_attr_starts_with_number branch from e6359fa to 5188421 Compare October 29, 2022 08:24
@zhmushan zhmushan requested review from chu121su12 and sudongyuer and removed request for antfu and chu121su12 October 29, 2022 16:29
@antfu antfu merged commit 3de4429 into unocss:main Oct 31, 2022
@zhmushan zhmushan deleted the vscode_attr_starts_with_number branch November 1, 2022 02:38
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.

None yet

4 participants