From 17c5d64fb22c097130f085fee040bce14f68b0d6 Mon Sep 17 00:00:00 2001 From: danielntmd Date: Thu, 2 Apr 2026 13:28:03 +0000 Subject: [PATCH] chore: single character url join urlJoin now properly appends single characters --- yarn-project/foundation/src/string/index.test.ts | 9 +++++++++ yarn-project/foundation/src/string/index.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) 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)); } }