Skip to content
Snippets Groups Projects
Commit 87d6da3a authored by Stephanie Freitag's avatar Stephanie Freitag
Browse files

HOLI-10917: handle URI encoding

parent 91a4636f
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,11 @@ describe('coerceUUIDParams', () => { ...@@ -5,10 +5,11 @@ describe('coerceUUIDParams', () => {
it('should replace invalid UUID param', () => { it('should replace invalid UUID param', () => {
const uuid = createUUID() const uuid = createUUID()
const invalid = `${uuid},` const invalid = `${uuid},`
const url = `/path/${encodeURIComponent(invalid)}`
const url = coerceUUIDParams([invalid], `/path/${invalid}`) const redirectUrl = coerceUUIDParams([invalid], url)
expect(url).toEqual(`/path/${uuid}`) expect(redirectUrl).toEqual(`/path/${uuid}`)
}) })
it('should replace multiple invalid UUID params', () => { it('should replace multiple invalid UUID params', () => {
...@@ -16,10 +17,11 @@ describe('coerceUUIDParams', () => { ...@@ -16,10 +17,11 @@ describe('coerceUUIDParams', () => {
const uuid2 = createUUID() const uuid2 = createUUID()
const invalid1 = `${uuid1},` const invalid1 = `${uuid1},`
const invalid2 = `${uuid2}👀` const invalid2 = `${uuid2}👀`
const url = `/path/${encodeURIComponent(invalid2)}/${encodeURIComponent(invalid1)}`
const url = coerceUUIDParams([invalid1, invalid2], `/path/${invalid2}/${invalid1}`) const redirectUrl = coerceUUIDParams([invalid1, invalid2], url)
expect(url).toEqual(`/path/${uuid2}/${uuid1}`) expect(redirectUrl).toEqual(`/path/${uuid2}/${uuid1}`)
}) })
it('should return undefined if all params are valid', () => { it('should return undefined if all params are valid', () => {
......
...@@ -266,7 +266,7 @@ describe('createServerSideProps', () => { ...@@ -266,7 +266,7 @@ describe('createServerSideProps', () => {
const uuid2 = createUUID() const uuid2 = createUUID()
const param1 = `${uuid1},` const param1 = `${uuid1},`
const param2 = `${uuid2}👀` const param2 = `${uuid2}👀`
const url = `/path/${param1}/${param2}` const url = `/path/${encodeURIComponent(param1)}/${encodeURIComponent(param2)}`
const expectedUrl = `/path/${uuid1}/${uuid2}` const expectedUrl = `/path/${uuid1}/${uuid2}`
// @ts-ignore // @ts-ignore
......
...@@ -10,7 +10,7 @@ const getSingleParam = (path: string | string[] | undefined) => { ...@@ -10,7 +10,7 @@ const getSingleParam = (path: string | string[] | undefined) => {
export const coerceUUIDParams = (uuidParams: (string | string[] | undefined)[], url?: string): string | undefined => { export const coerceUUIDParams = (uuidParams: (string | string[] | undefined)[], url?: string): string | undefined => {
const replacements = uuidParams const replacements = uuidParams
.map((param) => { .map((param) => {
const singleParam = getSingleParam(param) const singleParam = encodeURIComponent(getSingleParam(param) || '')
if (!singleParam) { if (!singleParam) {
return undefined return undefined
} }
...@@ -26,5 +26,5 @@ export const coerceUUIDParams = (uuidParams: (string | string[] | undefined)[], ...@@ -26,5 +26,5 @@ export const coerceUUIDParams = (uuidParams: (string | string[] | undefined)[],
return undefined return undefined
} }
return replacements.reduce((url, [invalid, valid]) => url?.replace(invalid, valid), url) return replacements.reduce((u, [invalid, valid]) => u?.replace(invalid, valid), url)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment