Skip to content

Commit

Permalink
fix behavior of slashJoin if only one path segment given
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo committed Feb 1, 2021
1 parent 2297f63 commit 2eebeb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/path-slashes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ describe('withoutSlashes', () => {
describe('slashJoin', () => {
it('should join path parts and add slashes if necessary', () => {
expect(slashJoin('foo/', '/bar', 'baz', '/boom')).toBe('foo/bar/baz/boom');
expect(slashJoin('foo/')).toBe('foo/');
expect(slashJoin('/foo/')).toBe('/foo/');
expect(slashJoin('/foo')).toBe('/foo');
expect(slashJoin('/foo/', '/bar', 'baz', '/boom')).toBe('/foo/bar/baz/boom');
expect(slashJoin(['foo/', '/bar', 'baz', '/boom'])).toBe('foo/bar/baz/boom');
expect(slashJoin(['foo/', '/bar', 'baz', '/boom/'])).toBe('foo/bar/baz/boom/');
Expand Down
2 changes: 1 addition & 1 deletion src/path-slashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function slashJoin(...strings: (string | string[])[]): string {
return parts
.map((part, i) => {
if (i === 0) {
return withoutTrailingSlash(part);
return parts.length === 1 ? part : withoutTrailingSlash(part);
} else if (i === parts.length - 1) {
return withoutLeadingSlash(part);
} else {
Expand Down

0 comments on commit 2eebeb5

Please sign in to comment.