Skip to content

Commit 0124387

Browse files
crossid-cicdasaf
authored andcommitted
fix: url encoding for arrays
Authorization url expects audience to be separated by space rather comma.
1 parent 2241158 commit 0124387

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/url.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
export const createQueryString = (qp: object) => {
33
return Object.keys(qp)
44
.filter((k) => qp[k] !== undefined && qp[k] !== null)
5-
.map((k) => encodeURIComponent(k) + '=' + encodeURIComponent(qp[k]))
5+
.map(
6+
(k) =>
7+
encodeURIComponent(k) +
8+
'=' +
9+
encodeURIComponent(Array.isArray(qp[k]) ? qp[k].join(' ') : qp[k])
10+
)
611
.join('&')
712
}

test/url.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ describe('createQueryString', () => {
66
createQueryString({
77
s: 'foo',
88
u: 'https://bar.baz',
9+
ua: ['https://bar.baz1', 'https://bar.baz2'],
910
n: 1,
1011
un: undefined,
1112
nu: null,
1213
})
13-
).toBe('s=foo&u=https%3A%2F%2Fbar.baz&n=1')
14+
).toBe(
15+
's=foo&u=https%3A%2F%2Fbar.baz&ua=https%3A%2F%2Fbar.baz1%20https%3A%2F%2Fbar.baz2&n=1'
16+
)
1417
})
1518
})

0 commit comments

Comments
 (0)