-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Escape path for the file list #22741
Changes from all commits
56d5479
281b0c3
947f01b
1b4551e
794de46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {describe, expect, test} from 'vitest'; | ||
import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted} from './repo-findfile.js'; | ||
import {strSubMatch, calcMatchedWeight, filterRepoFilesWeighted, escapePath} from './repo-findfile.js'; | ||
|
||
describe('Repo Find Files', () => { | ||
test('strSubMatch', () => { | ||
|
@@ -32,4 +32,9 @@ describe('Repo Find Files', () => { | |
expect(res).toHaveLength(2); | ||
expect(res[0].matchResult).toEqual(['', 'word', '.txt']); | ||
}); | ||
|
||
test('escapePath', () => { | ||
expect(escapePath('a/b/c')).toEqual('a/b/c'); | ||
expect(escapePath('a/b/ c')).toEqual('a/b/%20c'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about add a test for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not necessary .... encodeURIComponent already does the right thing. Otherwise there will be a lot like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From another perspective, if a users reports about If you want to test Test cases are designed for what it should be , but not what users said what happened. I can see many test cases in old code are not well designed, sometimes some developers just copy complex contents as test case data, which make the cases difficult to be maintained, and make future developers can not understand what the cases are for. In a word: keep things simple and focused. |
||
}); | ||
}); |
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.
Move function to
utils.js
? I think such simple pure functions belong there so they can be imported everywere easily without circular dependencies.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.
I have thought about it, but I didn't do it for 2 reasons:
escapePath
is only used byrepo-findfile.js
, not sure whether it is general enough for frontend.utils.js
have already contained many different functions, maybe in the future it should be refactored toutils/color.js
,utils/string.js
,utils/html.js
, etc. I do not feel it's good to add too many functions to it now.So, I prefer to keep the escapePath here. If it's really needed to be used somewhere else, let's do refactor.