From: Daniel Kutyła Date: Wed, 24 Mar 2021 21:50:56 +0000 (+0100) Subject: 17337: Added another edge case handling X-Git-Tag: 2.1.2.1~4^2~8 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/bde7ca868a0c201544476da6c049a98c1188dde9 17337: Added another edge case handling Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index 8c002362..6bfe5581 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -170,7 +170,7 @@ describe('Collection panel tests', function () { }) }) - it('renames a file using valid names', function () { + it.only('renames a file using valid names', function () { function eachPair(lst, func){ for(var i=0; i < lst.length - 1; i++){ func(lst[i], lst[i + 1]) diff --git a/src/common/url.test.ts b/src/common/url.test.ts index 80181a74..b0f8ae25 100644 --- a/src/common/url.test.ts +++ b/src/common/url.test.ts @@ -30,11 +30,11 @@ describe('url', () => { }); }); - describe('customEncodeURI', () => { - it('should decode', () => { + describe('customDecodeURI', () => { + it('should decode encoded URI', () => { // given const path = 'test%23test%2Ftest'; - const expectedResult = 'test#test/test'; + const expectedResult = 'test#test%2Ftest'; // when const result = customDecodeURI(path); @@ -42,10 +42,21 @@ describe('url', () => { // then expect(result).toEqual(expectedResult); }); + + it('ignores non parsable URI and return its original form', () => { + // given + const path = 'test/path/with%wrong/sign'; + + // when + const result = customDecodeURI(path); + + // then + expect(result).toEqual(path); + }); }); describe('customEncodeURI', () => { - it('should encode', () => { + it('should encode URI', () => { // given const path = 'test#test/test'; const expectedResult = 'test%23test/test'; @@ -56,5 +67,16 @@ describe('url', () => { // then expect(result).toEqual(expectedResult); }); + + it('ignores non encodable URI and return its original form', () => { + // given + const path = 22; + + // when + const result = customEncodeURI(path as any); + + // then + expect(result).toEqual(path); + }); }); }); \ No newline at end of file diff --git a/src/common/url.ts b/src/common/url.ts index 7a9a5158..16dc6170 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -20,7 +20,7 @@ export function normalizeURLPath(url: string) { export const customEncodeURI = (path: string) => { try { - return encodeURIComponent(path).replace(/%2F/g, '/'); + return path.split('/').map(encodeURIComponent).join('/'); } catch(e) {} return path; @@ -28,7 +28,7 @@ export const customEncodeURI = (path: string) => { export const customDecodeURI = (path: string) => { try { - return decodeURIComponent(path.replace(/\//g, '%2F')); + return path.split('%2F').map(decodeURIComponent).join('%2F'); } catch(e) {} return path; diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts index 9a05fb61..9583b7a4 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -28,7 +28,8 @@ export const extractFilesData = (document: Document) => { .map(element => { const name = getTagValue(element, 'D:displayname', ''); const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10); - const url = customDecodeURI(getTagValue(element, 'D:href', '')); + const href = getTagValue(element, 'D:href', ''); + const url = customDecodeURI(href); const nameSuffix = name; const collectionUuidMatch = collectionUrlPrefix.exec(url); const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';