Skip to content

Commit 17c5d64

Browse files
author
danielntmd
committed
chore: single character url join
urlJoin now properly appends single characters
1 parent 30021e0 commit 17c5d64

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

yarn-project/foundation/src/string/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ describe('string', () => {
1212
])('removes duplicate slashes', (parts, url) => {
1313
expect(urlJoin(...parts)).toBe(url);
1414
});
15+
16+
it.each([
17+
[['http://example.com', 'a'], 'http://example.com/a'],
18+
[['http://example.com', 'a', 'b'], 'http://example.com/a/b'],
19+
[['x', 'y', 'z'], 'x/y/z'],
20+
[['http://example.com', '/a/'], 'http://example.com/a'],
21+
])('preserves single-character path segments %#', (parts, url) => {
22+
expect(urlJoin(...parts)).toBe(url);
23+
});
1524
});
1625

1726
describe('hex prefix helpers', () => {

yarn-project/foundation/src/string/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function urlJoin(...args: string[]): string {
5858
end--;
5959
}
6060

61-
if (start < end) {
61+
if (start <= end) {
6262
processed.push(arg.slice(start, end + 1));
6363
}
6464
}

0 commit comments

Comments
 (0)