diff --git a/yarn-project/foundation/src/string/index.test.ts b/yarn-project/foundation/src/string/index.test.ts index 498e62e8d30a..f9921bd24fa7 100644 --- a/yarn-project/foundation/src/string/index.test.ts +++ b/yarn-project/foundation/src/string/index.test.ts @@ -12,6 +12,15 @@ describe('string', () => { ])('removes duplicate slashes', (parts, url) => { expect(urlJoin(...parts)).toBe(url); }); + + it.each([ + [['http://example.com', 'a'], 'http://example.com/a'], + [['http://example.com', 'a', 'b'], 'http://example.com/a/b'], + [['x', 'y', 'z'], 'x/y/z'], + [['http://example.com', '/a/'], 'http://example.com/a'], + ])('preserves single-character path segments %#', (parts, url) => { + expect(urlJoin(...parts)).toBe(url); + }); }); describe('hex prefix helpers', () => { diff --git a/yarn-project/foundation/src/string/index.ts b/yarn-project/foundation/src/string/index.ts index 2b1c69093e8c..06030d8cac3a 100644 --- a/yarn-project/foundation/src/string/index.ts +++ b/yarn-project/foundation/src/string/index.ts @@ -58,7 +58,7 @@ export function urlJoin(...args: string[]): string { end--; } - if (start < end) { + if (start <= end) { processed.push(arg.slice(start, end + 1)); } }