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: decode file names before displaying them. #4104

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions packages/__utils/src/uriHelper.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ describe('Validate uriHelper', () => {
});

test.each`
uri | segments | expected
${'file:///a/b/c/file.txt'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/'} | ${undefined} | ${'a/b'}
${'file:///a/b'} | ${undefined} | ${'a/b'}
${'file:///a/b/c/file.txt'} | ${3} | ${'b/c/file.txt'}
${'file:///a/b/c/file.txt'} | ${1} | ${'file.txt'}
${'file:///a/b/c/file.txt#156'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/c/file.txt?x=1'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/c/file.txt#156'} | ${{ relativeTo: 'file:///a/b/c/' }} | ${'file.txt'}
${'file:///a/b/c/file.txt#156'} | ${{ relativeTo: 'stdin:///a/b/c/' }} | ${'c/file.txt'}
uri | segments | expected
${'file:///a/b/c/file.txt'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/c/長いファイル名前.md'} | ${undefined} | ${'c/長いファイル名前.md'}
${'file:///a/b/'} | ${undefined} | ${'a/b'}
${'file:///a/b'} | ${undefined} | ${'a/b'}
${'file:///a/b/c/file.txt'} | ${3} | ${'b/c/file.txt'}
${'file:///a/b/c/file.txt'} | ${1} | ${'file.txt'}
${'file:///a/b/c/file.txt#156'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/c/file.txt?x=1'} | ${undefined} | ${'c/file.txt'}
${'file:///a/b/c/file.txt#156'} | ${{ relativeTo: 'file:///a/b/c/' }} | ${'file.txt'}
${'file:///a/b/c/file.txt#156'} | ${{ relativeTo: 'stdin:///a/b/c/' }} | ${'c/file.txt'}
`('uriToName "$uri" -> "$expected"', ({ uri, segments, expected }) => {
const uriA = toUri(uri);
expect(uriToName(uriA, typeof segments === 'number' ? { segments } : segments)).toBe(expected);
Expand Down
4 changes: 2 additions & 2 deletions packages/__utils/src/uriHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export function uriToName(uri: Uri, options: UriToNameOptions = {}): string {
if (relTo) {
const rel = relativeTo(toUri(relTo), uri);
if (!regExpIsUri.test(rel)) {
return rel.split('/').slice(-segments).join('/');
return decodeURIComponent(rel.split('/').slice(-segments).join('/'));
}
}
const parts = splitUri(uri).slice(-segments);
return parts.join('/');
return decodeURIComponent(parts.join('/'));
}

function splitUri(uri: Uri) {
Expand Down
3 changes: 2 additions & 1 deletion samples/custom-dictionary/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
],
"cSpell.customWorkspaceDictionaries": [
"words"
]
],
"cSpell.blockCheckingWhenLineLengthGreaterThan": 1000
}
1 change: 1 addition & 0 deletions samples/custom-dictionary/長いファイル名前.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a sample file with Japanese character names.