diff --git a/src/catu.test.ts b/src/catu.test.ts index edf1eca..1cd55c9 100644 --- a/src/catu.test.ts +++ b/src/catu.test.ts @@ -243,10 +243,17 @@ describe('Common Access Token Uri', () => { test('can match query params', async () => { const catu = CommonAccessTokenUri.fromDict({ query: { - 'exact-match': 'z=z&x=true&y=false' + 'exact-match': '?z=z&x=true&y=false' } }); const uri = new URL('https://example.com/path?y=false&x=true&z=z'); expect(await catu.match(uri)).toBeTruthy(); + const catu2 = CommonAccessTokenUri.fromDict({ + query: { + 'exact-match': 'z=z&x=true&y=false' + } + }); + const uri2 = new URL('https://example.com/path?y=false&x=true&z=z'); + expect(await catu2.match(uri2)).toBeTruthy(); }); }); diff --git a/src/catu.ts b/src/catu.ts index c7c2de5..1ee58f1 100644 --- a/src/catu.ts +++ b/src/catu.ts @@ -147,8 +147,11 @@ export class CommonAccessTokenUri { params.delete('cat'); params.sort(); value = params.toString(); + const matchValueString = matchValue as string; const matchValueParams = new URLSearchParams( - '?' + (matchValue as string) + !matchValueString.startsWith('?') + ? '?' + matchValueString + : matchValueString ); matchValueParams.sort(); matchValue = matchValueParams.toString();