Skip to content

Commit

Permalink
fix: correct the URI encoding (#5102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Dec 21, 2023
1 parent e93bdd0 commit c0c3427
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/cspell-lib/src/lib/util/Uri.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ describe('Uri', () => {
test.each`
uri | expected
${toUri('file:///d:/a/src/sample.c').toString()} | ${new URL('file:///d:/a/src/sample.c').toString()}
${toUri('file:///d:/a%20b/%23src/[email protected]').toString()} | ${new URL('file:///d:/a%20b/%23src/[email protected]').toString()}
${toUri('file:///d:/a/src/sample.c').toString()} | ${'file:///d:/a/src/sample.c'}
${toUri('file:///d:/a/src files/sample.c').toString()} | ${new URL('file:///d:/a/src files/sample.c').toString()}
${toUri('https://g.com/maps?lat=43.23&lon=-0.5#first').toString()} | ${new URL('https://g.com/maps?lat=43.23&lon=-0.5#first').toString()}
${uriToFilePath(fromFilePath(__filename))} | ${eqCI(__filename)}
${uriToFilePath(fromFilePath(pTestFixtures('issues/issue-4811/@local?/README.md')))} | ${normalizeDriveLetter(pTestFixtures('issues/issue-4811/@local?/README.md'))}
${uriToFilePath(fromFilePath(pTestFixtures('issues/issue-4811/#local/README.md')))} | ${normalizeDriveLetter(pTestFixtures('issues/issue-4811/#local/README.md'))}
${uriToFilePath(fromFilePath(pTestFixtures('issues/issue-4811/#+,=&@;?v/README.md')))} | ${normalizeDriveLetter(pTestFixtures('issues/issue-4811/#+,=&@;?v/README.md'))}
${urlFile(pTestFixtures('issues/issue-4811/#local/README.md')).href} | ${sc('/%23local/README.md')}
${URI.parse(urlFile(pTestFixtures('issues/issue-4811/#local/README.md')).href).toString()} | ${sc('/%23local/README.md')}
${URI.file(pTestFixtures('issues/issue-4811/#local/README.md')).toString()} | ${sc('/%23local/README.md')}
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/lib/util/Uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class UriImpl extends URI implements UriInstance {

toString(): string {
// if (this.scheme !== 'stdin') return super.toString(true);
const path = (this.path || '').split('/').map(encodeURIComponent).join('/').replace(/%3A/g, ':');
const path = encodeURI(this.path || '').replace(/[#?]/g, (c) => `%${c.charCodeAt(0).toString(16)}`);
const base = `${this.scheme}://${this.authority || ''}${path}`;
const query = (this.query && `?${this.query}`) || '';
const fragment = (this.fragment && `#${this.fragment}`) || '';
Expand Down

0 comments on commit c0c3427

Please sign in to comment.