17337: Added another edge case handling
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 24 Mar 2021 21:50:56 +0000 (22:50 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 24 Mar 2021 21:50:56 +0000 (22:50 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/collection.spec.js
src/common/url.test.ts
src/common/url.ts
src/services/collection-service/collection-service-files-response.ts

index 8c002362f2d7b20726ac9c006415e330b8890f3d..6bfe55814e345414a3759b447a3b0403034cd331 100644 (file)
@@ -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])
index 80181a746ad698650f143bfb41a9f39cbb3177c3..b0f8ae251af7e9a5b054c0cc2cb74ee78d20bbf6 100644 (file)
@@ -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
index 7a9a5158a6ad8a184b2d23ef87a8a7c709e8ba76..16dc6170a4d5f38d6fbc4324e133b7c8d68d4a8a 100644 (file)
@@ -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;
index 9a05fb61efc95e7be00ce5186d5ef020cf69a56f..9583b7a4ebd749ffaa2898ad176830c4214f8573 100644 (file)
@@ -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() : '';