17337: Added % sign handling in collection files
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 23 Mar 2021 22:12:23 +0000 (23:12 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Tue, 23 Mar 2021 22:12:23 +0000 (23:12 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/common/url.test.ts
src/common/url.ts
src/common/webdav.ts
src/common/xml.ts
src/components/tree/virtual-tree.tsx
src/services/collection-service/collection-service-files-response.ts

index 4753096647bb92952c68678f3a92a6e3a5d63022..80181a746ad698650f143bfb41a9f39cbb3177c3 100644 (file)
@@ -48,7 +48,7 @@ describe('url', () => {
         it('should encode', () => {
             // given
             const path = 'test#test/test';
-            const expectedResult = 'test%23test%2Ftest';
+            const expectedResult = 'test%23test/test';
 
             // when
             const result = customEncodeURI(path);
index 0d2549c1b9fc55cb6b123833ab30e29d4e3aa083..7a9a5158a6ad8a184b2d23ef87a8a7c709e8ba76 100644 (file)
@@ -19,11 +19,19 @@ export function normalizeURLPath(url: string) {
 }
 
 export const customEncodeURI = (path: string) => {
-    return encodeURIComponent(path.replace(/%2F/g, '/'));
+    try {
+        return encodeURIComponent(path).replace(/%2F/g, '/');
+    } catch(e) {}
+
+    return path;
 };
 
 export const customDecodeURI = (path: string) => {
-    return decodeURIComponent(path.replace(/\//g, '%2F'));
+    try {
+        return decodeURIComponent(path.replace(/\//g, '%2F'));
+    } catch(e) {}
+
+    return path;
 };
 
 export const encodeHash = (path: string) => {
index ca3b6d74686093ad75b3776faa29499ca9684de6..8d071fa635ce2f0dc58085e447f981191d96e8a7 100644 (file)
@@ -79,7 +79,7 @@ export class WebDAV {
                     ? this.defaults.baseURL+'/'
                     : ''}${customEncodeURI(config.url)}`);
 
-            if (config.headers && config.headers.Destination && config.headers.Destination.indexOf('#') > -1) {
+            if (config.headers && config.headers.Destination) {
                 config.headers.Destination = encodeHash(config.headers.Destination);
             }
 
index 3c6feb5dce8836a92a08074ba32a768af4ec84fc..751a327c77cb48ec64cc23611bb4834c5388e093 100644 (file)
@@ -4,7 +4,13 @@
 
 export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => {
     const [el] = Array.from(document.getElementsByTagName(tagName));
-    return decodeURI(el ? htmlDecode(el.innerHTML) : defaultValue);
+    const URI = el ? htmlDecode(el.innerHTML) : defaultValue;
+
+    try {
+        return decodeURI(URI);
+    } catch(e) {}
+
+    return URI;
 };
 
 const htmlDecode = (input: string) => {
index 54938969ffded1d38c47cf1172d1fc160a7f1990..4e4500b7289f5502cad1142e9506ae98a9d6a82d 100644 (file)
@@ -182,7 +182,6 @@ export const VirtualTree = withStyles(styles)(
     class Component<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
         render(): ReactElement<any> {
             const { items, render } = this.props;
-
             return <AutoSizer>
                 {({ height, width }) => {
                     return VirtualList(height, width, items || [], render, this.props);
index 0dd7260b022c63e231373504449716182387ef90..9a05fb61efc95e7be00ce5186d5ef020cf69a56f 100644 (file)
@@ -34,7 +34,8 @@ export const extractFilesData = (document: Document) => {
             const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';
             const directory = url
                 .replace(collectionUrlPrefix, '')
-                .replace(nameSuffix, '');
+                .replace(nameSuffix, '')
+                .replace(/\/\//g, '/');
 
             const parentPath = directory.replace(/\/$/, '');
             const data = {
@@ -48,9 +49,11 @@ export const extractFilesData = (document: Document) => {
                 path: parentPath,
             };
 
-            return getTagValue(element, 'D:resourcetype', '')
+            const result = getTagValue(element, 'D:resourcetype', '')
                 ? createCollectionDirectory(data)
                 : createCollectionFile({ ...data, size });
+
+            return result;
         });
 };