Skip to content

Commit

Permalink
fix: Fix uri to json conversion when no required params are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Feb 3, 2024
1 parent 394fcb7 commit 36a70ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/common/lib/__tests__/Encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { convertURIToJsonObject } from '../functions';

import { UNIT_TEST_TIMEOUT } from './CredentialOfferUtil.spec';

describe('URI to json enconding', () => {
const CREDENTIAL_OFFER_CODE = 'openid-credential-offer://code=1234-1234-1234';

it(
'should get code from auth-code redirect URI',
async () => {
expect(convertURIToJsonObject(CREDENTIAL_OFFER_CODE)).toEqual({ code: '1234-1234-1234' });
},
UNIT_TEST_TIMEOUT,
);
});
2 changes: 1 addition & 1 deletion packages/common/lib/functions/Encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function convertJsonToURI(
* - arrayTypeProperties: properties that can show up more that once
*/
export function convertURIToJsonObject(uri: string, opts?: DecodeURIAsJsonOpts): unknown {
if (!uri || !opts?.requiredProperties?.every((p) => uri.includes(p))) {
if (!uri || (opts?.requiredProperties && !opts.requiredProperties?.every((p) => uri.includes(p)))) {
throw new Error(BAD_PARAMS);
}
const uriComponents = getURIComponentsAsArray(uri, opts?.arrayTypeProperties);
Expand Down

0 comments on commit 36a70ca

Please sign in to comment.