Skip to content

Commit 1ae217d

Browse files
authored
Remove only trailing slashes (#3183)
1 parent 862e717 commit 1ae217d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/filesystem/__tests__/path-utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ describe('Path Utilities', () => {
7070
.toBe('/home/user/some path');
7171
expect(normalizePath('"/usr/local/some app/"'))
7272
.toBe('/usr/local/some app');
73+
expect(normalizePath('/usr/local//bin/app///'))
74+
.toBe('/usr/local/bin/app');
75+
expect(normalizePath('/'))
76+
.toBe('/');
77+
expect(normalizePath('///'))
78+
.toBe('/');
7379
});
7480

7581
it('removes surrounding quotes', () => {

src/filesystem/path-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function normalizePath(p: string): string {
5555
if (isUnixPath) {
5656
// For Unix paths, just normalize without converting to Windows format
5757
// Replace double slashes with single slashes and remove trailing slashes
58-
return p.replace(/\/+/g, '/').replace(/\/+$/, '');
58+
return p.replace(/\/+/g, '/').replace(/(?<!^)\/$/, '');
5959
}
6060

6161
// Convert Unix-style Windows paths (/c/, /d/) to Windows format if on Windows

0 commit comments

Comments
 (0)