Skip to content
Open
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
18 changes: 18 additions & 0 deletions src/test/suite/pathUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ describe('GetWorkspaceFromRelativePath / GetWorkspaceFromAbsolutePath', () => {
});
});

describe('EscapePathParts / UnescapePathParts', () => {
it('escapes # in a path segment so it is not treated as a URL fragment delimiter', () => {
const actual = PathUtil.EscapePathParts('my#folder/index.html');
assert.strictEqual(actual, 'my%23folder/index.html');
});

it('round-trips a path segment containing #', () => {
const escaped = PathUtil.EscapePathParts('my#folder/index.html');
const actual = PathUtil.UnescapePathParts(escaped);
assert.strictEqual(actual, 'my#folder/index.html');
});

it('escapes a leading # the same as one in the middle of a segment', () => {
const actual = PathUtil.EscapePathParts('#folder/index.html');
assert.strictEqual(actual, '%23folder/index.html');
});
});

describe('getEndpointParent', () => {
it('returns the correct endpoint parent for full paths', async () => {
const endpoint1 = PathUtil.GetEndpointParent('c:/Users/TestUser/workspace1/');
Expand Down
4 changes: 2 additions & 2 deletions src/utils/pathUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PathUtil {

const newParts = parts
.filter((part) => part.length > 0)
.map((filterdPart) => encodeURI(filterdPart));
.map((filterdPart) => encodeURIComponent(filterdPart));
return newParts.join('/');
}

Expand All @@ -39,7 +39,7 @@ export class PathUtil {
const parts = file.split('/');
const newParts = parts
.filter((part) => part.length > 0)
.map((filterdPart) => decodeURI(filterdPart));
.map((filterdPart) => decodeURIComponent(filterdPart));
return newParts.join('/');
}

Expand Down