Skip to content

Commit e03b217

Browse files
committed
fix: fix urlJoin issue
1 parent 158c51f commit e03b217

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,12 @@ export default class Qsu {
843843

844844
const argLength = args.length;
845845
let urlResult = '';
846+
let joinCount = 0;
846847

847848
for (let i = 0; i < argLength; i += 1) {
848849
if (args[i] !== null && args[i] !== undefined) {
849850
if (
850-
i === 0 ||
851+
joinCount === 0 ||
851852
args[i].startsWith('/') ||
852853
args[i].startsWith('?') ||
853854
args[i].startsWith('&')
@@ -856,6 +857,8 @@ export default class Qsu {
856857
} else {
857858
urlResult += `/${args[i]}`;
858859
}
860+
861+
joinCount += 1;
859862
}
860863
}
861864

test/string.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ st`),
245245
it('urlJoin', (done) => {
246246
assert.strictEqual(urlJoin('https://example.com'), 'https://example.com');
247247
assert.strictEqual(urlJoin('https://example.com', null, 'world/'), 'https://example.com/world');
248+
assert.strictEqual(urlJoin(null, 'https://example.com', 'world/'), 'https://example.com/world');
248249
assert.strictEqual(
249250
urlJoin('https://example.com', 'hello', 'world'),
250251
'https://example.com/hello/world'

0 commit comments

Comments
 (0)