-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add transformWin32RelativePath #15
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
base: main
Are you sure you want to change the base?
Conversation
cfa3a99 to
cbe265e
Compare
src/normalize.ts
Outdated
|
|
||
| export function normalizeWin32RelativePath(p: string): string { | ||
| return p.replace( | ||
| /(['"`])(\.\.([\\/]))+([\w-]+\3)+[^\\/]*\1/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this was just my temporary workaround for that issue, it didn't cover one level sibling relative path: ./.
| /(['"`])(\.\.([\\/]))+([\w-]+\3)+[^\\/]*\1/g, | |
| /(['"`])(\.\.?([\\/]))+([\w-]+\3?)+[^\\/]*\1/g, |
…ession Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ession Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| return p.replace( | ||
| /(['"`])(\.\.?([\\/]))+((?:[^\W_]|-)+\3?)+[^\\/]*\1/g, | ||
| (match: string) => { | ||
| return match.replace(/\\/g, '/'); | ||
| }, | ||
| ); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data High
regular expression
library input
|
|
||
| export function normalizeWin32RelativePath(p: string): string { | ||
| return p.replace( | ||
| /(['"`])(\.\.?([\\/]))+((?:[^\W_]|-)+\3?)+[^\\/]*\1/g, |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, we need to remove the ambiguity in the regular expression. The problematic part (?:[^\W_]|-)+ can be rewritten to explicitly match either alphanumeric characters or hyphens without ambiguity. This can be achieved by replacing [^\W_] with a more specific character class, such as [a-zA-Z0-9], and ensuring that the hyphen - is handled separately. The updated regular expression will avoid exponential backtracking while maintaining the intended functionality.
The specific change will be made on line 24 of src/normalize.ts.
-
Copy modified line R24
| @@ -23,3 +23,3 @@ | ||
| return p.replace( | ||
| /(['"`])(\.\.?([\\/]))+((?:[^\W_]|-)+\3?)+[^\\/]*\1/g, | ||
| /(['"`])(\.\.?([\\/]))+([a-zA-Z0-9-]+\3?)+[^\\/]*\1/g, | ||
| (match: string) => { |
close #10