-
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
Open
SoonIter
wants to merge
4
commits into
main
Choose a base branch
from
syt/add-beforeSerialize-afterSerialize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−50
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbe265e
feat: add transformWin32RelativePath
SoonIter 905207a
feat: add transformWin32RelativePath
SoonIter 8fd1f45
Potential fix for code scanning alert no. 5: Inefficient regular expr…
SoonIter 4cba783
Potential fix for code scanning alert no. 7: Inefficient regular expr…
SoonIter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import path from 'node:path'; | ||
| import { expect } from 'vitest'; | ||
| import { test } from 'vitest'; | ||
| import { createSnapshotSerializer } from 'path-serializer'; | ||
| import { describe, expect } from 'vitest'; | ||
| import { test } from 'vitest'; | ||
|
|
||
| expect.addSnapshotSerializer( | ||
| createSnapshotSerializer({ | ||
|
|
@@ -13,44 +13,44 @@ expect.addSnapshotSerializer( | |
| }), | ||
| ); | ||
|
|
||
| test('should serialize file content without escaping \\"', () => { | ||
| const fileContent = `"use strict"; | ||
| const a = "${require.resolve('@rslib/core')}"; | ||
| `; | ||
| test('transformWin32Path', () => { | ||
| const fileContent = `{ | ||
| loader: 'D:\\Users\\user\\Documents\\code\\user\\fe-dev-scripts\\src\\utils.ts', | ||
| }`; | ||
|
|
||
| expect(fileContent).toMatchInlineSnapshot(` | ||
| "use strict"; | ||
| const a = "<ROOT>/node_modules/<PNPM_INNER>/@rslib/core/dist/index.js"; | ||
| { | ||
| loader: '/d/Users/user/Documents/code/user/fe-dev-scripts/src/utils.ts', | ||
| } | ||
| `); | ||
| }); | ||
|
|
||
| test('should serialize webpack output content', () => { | ||
| const fileContent = `;// CONCATENATED MODULE: ../../../../node_modules/.pnpm/@[email protected]/node_modules/@swc/helpers/esm/_class_private_method_get.js | ||
| function _class_private_method_get(receiver, privateSet, fn) { | ||
| if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); | ||
| test('transformWin32RelativePath', () => { | ||
| const case1 = `Cannot find file "..\\..\\getting-started\\next"`; | ||
|
|
||
| return fn; | ||
| } | ||
| `; | ||
| expect(case1).toMatchInlineSnapshot( | ||
| `Cannot find file "../../getting-started/next"`, | ||
| ); | ||
|
|
||
| expect(fileContent).toMatchInlineSnapshot(` | ||
| ;// CONCATENATED MODULE: ../../../../node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js | ||
| function _class_private_method_get(receiver, privateSet, fn) { | ||
| if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); | ||
| const case2 = `Cannot find file "..\\getting-started\\next"`; | ||
| expect(case2).toMatchInlineSnapshot( | ||
| `Cannot find file "../getting-started/next"`, | ||
| ); | ||
|
|
||
| return fn; | ||
| } | ||
| `); | ||
| const case3 = `Cannot find file ".\\getting-started\\next"`; | ||
| expect(case3).toMatchInlineSnapshot( | ||
| `Cannot find file "./getting-started/next"`, | ||
| ); | ||
| }); | ||
|
|
||
| test('should serialize the Win32 path', () => { | ||
| const fileContent = `{ | ||
| loader: 'D:\\Users\\user\\Documents\\code\\user\\fe-dev-scripts\\src\\utils.ts', | ||
| }`; | ||
| describe('transformCLR', () => { | ||
| test('should transform the color', () => { | ||
| const input = '\u001b[1mBold Text\u001b[0m'; | ||
| expect(input).toMatchInlineSnapshot('<CLR=BOLD>Bold Text<CLR=0>'); | ||
| }); | ||
|
|
||
| expect(fileContent).toMatchInlineSnapshot(` | ||
| { | ||
| loader: '/d/Users/user/Documents/code/user/fe-dev-scripts/src/utils.ts', | ||
| } | ||
| `); | ||
| test('bad case 1', () => { | ||
| const input = 'static/react.svg'; // bad case: 'static/reactXsvg' | ||
| expect(input).toMatchInlineSnapshot('static/react.svg'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import path from 'node:path'; | ||
| import { createSnapshotSerializer } from 'path-serializer'; | ||
| import { expect } from 'vitest'; | ||
| import { test } from 'vitest'; | ||
|
|
||
| expect.addSnapshotSerializer( | ||
| createSnapshotSerializer({ | ||
| root: path.resolve(__dirname, '..'), | ||
| features: { | ||
| escapeDoubleQuotes: false, | ||
| addDoubleQuotes: false, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| test('should serialize file content without escaping \\"', () => { | ||
| const fileContent = `"use strict"; | ||
| const a = "${require.resolve('@rslib/core')}"; | ||
| `; | ||
|
|
||
| expect(fileContent).toMatchInlineSnapshot(` | ||
| "use strict"; | ||
| const a = "<ROOT>/node_modules/<PNPM_INNER>/@rslib/core/dist/index.js"; | ||
| `); | ||
| }); | ||
|
|
||
| test('should serialize webpack output content', () => { | ||
| const fileContent = `;// CONCATENATED MODULE: ../../../../node_modules/.pnpm/@[email protected]/node_modules/@swc/helpers/esm/_class_private_method_get.js | ||
| function _class_private_method_get(receiver, privateSet, fn) { | ||
| if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); | ||
|
|
||
| return fn; | ||
| } | ||
| `; | ||
|
|
||
| expect(fileContent).toMatchInlineSnapshot(` | ||
| ;// CONCATENATED MODULE: ../../../../node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js | ||
| function _class_private_method_get(receiver, privateSet, fn) { | ||
| if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance"); | ||
|
|
||
| return fn; | ||
| } | ||
| `); | ||
| }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Inefficient regular expression High
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.