Merge branch '17337-files-not-visible-in-arvados'
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 1 Apr 2021 20:49:33 +0000 (22:49 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 1 Apr 2021 20:49:51 +0000 (22:49 +0200)
closes #17337

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 [new file with mode: 0644]
src/common/url.ts
src/common/webdav.test.ts
src/common/webdav.ts
src/common/xml.ts
src/components/tree/virtual-tree.tsx
src/services/collection-service/collection-service-files-response.test.ts [new file with mode: 0644]
src/services/collection-service/collection-service-files-response.ts
src/services/collection-service/collection-service.ts

index 8db574ce9ff473201adc5b7e81f4e2002cc6a8f9..841197abcfdc5a0b130ce9759e7760bc93d48584 100644 (file)
@@ -2,68 +2,69 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-describe('Collection panel tests', function() {
+describe('Collection panel tests', function () {
     let activeUser;
     let adminUser;
 
-    before(function() {
+    before(function () {
         // Only set up common users once. These aren't set up as aliases because
         // aliases are cleaned up after every test. Also it doesn't make sense
         // to set the same users on beforeEach() over and over again, so we
         // separate a little from Cypress' 'Best Practices' here.
         cy.getUser('admin', 'Admin', 'User', true, true)
-            .as('adminUser').then(function() {
+            .as('adminUser').then(function () {
                 adminUser = this.adminUser;
             }
-        );
+            );
         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
-            .as('activeUser').then(function() {
+            .as('activeUser').then(function () {
                 activeUser = this.activeUser;
             }
-        );
+            );
     });
 
-    beforeEach(function() {
+    beforeEach(function () {
         cy.clearCookies();
         cy.clearLocalStorage();
     });
 
-    it('uses the property editor with vocabulary terms', function() {
+    it('uses the property editor with vocabulary terms', function () {
         cy.createCollection(adminUser.token, {
             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
             owner_uuid: activeUser.user.uuid,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
-        .as('testCollection').then(function() {
-            cy.loginAs(activeUser);
-            cy.doSearch(`${this.testCollection.uuid}`);
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection').then(function () {
+                cy.loginAs(activeUser);
+                cy.doSearch(`${this.testCollection.uuid}`);
 
-            // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
-            cy.get('[data-cy=resource-properties-form]').within(() => {
-                cy.get('[data-cy=property-field-key]').within(() => {
-                    cy.get('input').type('Color');
-                });
-                cy.get('[data-cy=property-field-value]').within(() => {
-                    cy.get('input').type('Magenta');
+                // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
+                cy.get('[data-cy=resource-properties-form]').within(() => {
+                    cy.get('[data-cy=property-field-key]').within(() => {
+                        cy.get('input').type('Color');
+                    });
+                    cy.get('[data-cy=property-field-value]').within(() => {
+                        cy.get('input').type('Magenta');
+                    });
+                    cy.root().submit();
                 });
-                cy.root().submit();
-            });
-            // Confirm proper vocabulary labels are displayed on the UI.
-            cy.get('[data-cy=collection-properties-panel]')
-                .should('contain', 'Color')
-                .and('contain', 'Magenta');
-            // Confirm proper vocabulary IDs were saved on the backend.
-            cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
-            .its('body').as('collection')
-            .then(function() {
-                expect(this.collection.properties).to.deep.equal(
-                    {IDTAGCOLORS: 'IDVALCOLORS3'});
+                // Confirm proper vocabulary labels are displayed on the UI.
+                cy.get('[data-cy=collection-properties-panel]')
+                    .should('contain', 'Color')
+                    .and('contain', 'Magenta');
+                // Confirm proper vocabulary IDs were saved on the backend.
+                cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
+                    .its('body').as('collection')
+                    .then(function () {
+                        expect(this.collection.properties).to.deep.equal(
+                            { IDTAGCOLORS: 'IDVALCOLORS3' });
+                    });
             });
-        });
     });
 
-    it('shows collection by URL', function() {
+    it('shows collection by URL', function () {
         cy.loginAs(activeUser);
-        [true, false].map(function(isWritable) {
+        [true, false].map(function (isWritable) {
             // Using different file names to avoid test flakyness: the second iteration
             // on this loop may pass an assertion from the first iteration by looking
             // for the same file name.
@@ -71,230 +72,262 @@ describe('Collection panel tests', function() {
             cy.createGroup(adminUser.token, {
                 name: 'Shared project',
                 group_class: 'project',
-            }).as('sharedGroup').then(function() {
+            }).as('sharedGroup').then(function () {
                 // Creates the collection using the admin token so we can set up
                 // a bogus manifest text without block signatures.
                 cy.createCollection(adminUser.token, {
                     name: 'Test collection',
                     owner_uuid: this.sharedGroup.uuid,
-                    properties: {someKey: 'someValue'},
-                    manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`})
-                .as('testCollection').then(function() {
-                    // Share the group with active user.
-                    cy.createLink(adminUser.token, {
-                        name: isWritable ? 'can_write' : 'can_read',
-                        link_class: 'permission',
-                        head_uuid: this.sharedGroup.uuid,
-                        tail_uuid: activeUser.user.uuid
-                    })
-                    cy.doSearch(`${this.testCollection.uuid}`);
-
-                    // Check that name & uuid are correct.
-                    cy.get('[data-cy=collection-info-panel]')
-                        .should('contain', this.testCollection.name)
-                        .and('contain', this.testCollection.uuid)
-                        .and('not.contain', 'This is an old version');
-                    // Check for the read-only icon
-                    cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
-                    // Check that both read and write operations are available on
-                    // the 'More options' menu.
-                    cy.get('[data-cy=collection-panel-options-btn]')
-                        .click()
-                    cy.get('[data-cy=context-menu]')
-                        .should('contain', 'Add to favorites')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
-                    cy.get('body').click(); // Collapse the menu avoiding details panel expansion
-                    cy.get('[data-cy=collection-properties-panel]')
-                        .should('contain', 'someKey')
-                        .and('contain', 'someValue')
-                        .and('not.contain', 'anotherKey')
-                        .and('not.contain', 'anotherValue')
-                    if (isWritable === true) {
-                        // Check that properties can be added.
-                        cy.get('[data-cy=resource-properties-form]').within(() => {
-                            cy.get('[data-cy=property-field-key]').within(() => {
-                                cy.get('input').type('anotherKey');
-                            });
-                            cy.get('[data-cy=property-field-value]').within(() => {
-                                cy.get('input').type('anotherValue');
-                            });
-                            cy.root().submit();
+                    properties: { someKey: 'someValue' },
+                    manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
+                })
+                    .as('testCollection').then(function () {
+                        // Share the group with active user.
+                        cy.createLink(adminUser.token, {
+                            name: isWritable ? 'can_write' : 'can_read',
+                            link_class: 'permission',
+                            head_uuid: this.sharedGroup.uuid,
+                            tail_uuid: activeUser.user.uuid
                         })
+                        cy.doSearch(`${this.testCollection.uuid}`);
+
+                        // Check that name & uuid are correct.
+                        cy.get('[data-cy=collection-info-panel]')
+                            .should('contain', this.testCollection.name)
+                            .and('contain', this.testCollection.uuid)
+                            .and('not.contain', 'This is an old version');
+                        // Check for the read-only icon
+                        cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
+                        // Check that both read and write operations are available on
+                        // the 'More options' menu.
+                        cy.get('[data-cy=collection-panel-options-btn]')
+                            .click()
+                        cy.get('[data-cy=context-menu]')
+                            .should('contain', 'Add to favorites')
+                            .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
+                        cy.get('body').click(); // Collapse the menu avoiding details panel expansion
                         cy.get('[data-cy=collection-properties-panel]')
-                            .should('contain', 'anotherKey')
-                            .and('contain', 'anotherValue')
-                    } else {
-                        // Properties form shouldn't be displayed.
-                        cy.get('[data-cy=resource-properties-form]').should('not.exist');
-                    }
-                    // Check that the file listing show both read & write operations
-                    cy.get('[data-cy=collection-files-panel]').within(() => {
-                        cy.root().should('contain', fileName);
-                        if (isWritable) {
-                            cy.get('[data-cy=upload-button]')
-                                .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
+                            .should('contain', 'someKey')
+                            .and('contain', 'someValue')
+                            .and('not.contain', 'anotherKey')
+                            .and('not.contain', 'anotherValue')
+                        if (isWritable === true) {
+                            // Check that properties can be added.
+                            cy.get('[data-cy=resource-properties-form]').within(() => {
+                                cy.get('[data-cy=property-field-key]').within(() => {
+                                    cy.get('input').type('anotherKey');
+                                });
+                                cy.get('[data-cy=property-field-value]').within(() => {
+                                    cy.get('input').type('anotherValue');
+                                });
+                                cy.root().submit();
+                            })
+                            cy.get('[data-cy=collection-properties-panel]')
+                                .should('contain', 'anotherKey')
+                                .and('contain', 'anotherValue')
+                        } else {
+                            // Properties form shouldn't be displayed.
+                            cy.get('[data-cy=resource-properties-form]').should('not.exist');
                         }
-                    });
-                    cy.get('[data-cy=collection-files-panel]')
-                        .contains(fileName).rightclick();
-                    cy.get('[data-cy=context-menu]')
-                        .should('contain', 'Download')
-                        .and('contain', 'Open in new tab')
-                        .and('contain', 'Copy to clipboard')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
-                    cy.get('body').click(); // Collapse the menu
-                    // Hamburger 'more options' menu button
-                    cy.get('[data-cy=collection-files-panel-options-btn]')
-                        .click()
-                    cy.get('[data-cy=context-menu]')
-                        .should('contain', 'Select all')
-                        .click()
-                    cy.get('[data-cy=collection-files-panel-options-btn]')
-                        .click()
-                    cy.get('[data-cy=context-menu]')
-                        // .should('contain', 'Download selected')
-                        .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
-                    cy.get('body').click(); // Collapse the menu
-                    // File item 'more options' button
-                    cy.get('[data-cy=file-item-options-btn')
-                        .click()
-                    cy.get('[data-cy=context-menu]')
-                        .should('contain', 'Download')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
-                    cy.get('body').click(); // Collapse the menu
-                })
+                        // Check that the file listing show both read & write operations
+                        cy.get('[data-cy=collection-files-panel]').within(() => {
+                            cy.root().should('contain', fileName);
+                            if (isWritable) {
+                                cy.get('[data-cy=upload-button]')
+                                    .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
+                            }
+                        });
+                        cy.get('[data-cy=collection-files-panel]')
+                            .contains(fileName).rightclick({ force: true });
+                        cy.get('[data-cy=context-menu]')
+                            .should('contain', 'Download')
+                            .and('contain', 'Open in new tab')
+                            .and('contain', 'Copy to clipboard')
+                            .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
+                            .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
+                        cy.get('body').click(); // Collapse the menu
+                        // Hamburger 'more options' menu button
+                        cy.get('[data-cy=collection-files-panel-options-btn]')
+                            .click()
+                        cy.get('[data-cy=context-menu]')
+                            .should('contain', 'Select all')
+                            .click()
+                        cy.get('[data-cy=collection-files-panel-options-btn]')
+                            .click()
+                        cy.get('[data-cy=context-menu]')
+                            // .should('contain', 'Download selected')
+                            .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
+                        cy.get('body').click(); // Collapse the menu
+                        // File item 'more options' button
+                        cy.get('[data-cy=file-item-options-btn')
+                            .click()
+                        cy.get('[data-cy=context-menu]')
+                            .should('contain', 'Download')
+                            .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
+                        cy.get('body').click(); // Collapse the menu
+                    })
             })
         })
     })
 
-    it('renames a file using valid names', function() {
+    it('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])
+            }
+        }
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
             owner_uuid: activeUser.user.uuid,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
-        .as('testCollection').then(function() {
-            cy.loginAs(activeUser);
-            cy.doSearch(`${this.testCollection.uuid}`);
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection').then(function () {
+                cy.loginAs(activeUser);
+                cy.doSearch(`${this.testCollection.uuid}`);
 
-            const nameTransitions = [
-                ['bar', '&'],
-                ['&', 'foo'],
-                ['foo', '&amp;'],
-                ['&amp;', 'I ❤️ ⛵️'],
-                ['I ❤️ ⛵️', '...']
-            ];
-            nameTransitions.forEach(([from, to]) => {
-                cy.get('[data-cy=collection-files-panel]')
-                    .contains(`${from}`).rightclick();
-                cy.get('[data-cy=context-menu]')
-                    .contains('Rename')
-                    .click();
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.get('input').type(`{selectall}{backspace}${to}`);
-                    });
-                cy.get('[data-cy=form-submit-btn]').click();
-                cy.get('[data-cy=collection-files-panel]')
-                    .should('not.contain', `${from}`)
-                    .and('contain', `${to}`);
-            })
-        });
+                const names = [
+                    'bar', // initial name already set
+                    '&',
+                    'foo',
+                    '&amp;',
+                    'I ❤️ ⛵️',
+                    '...',
+                    '#..',
+                    'some name with whitespaces',
+                    'some name with #2',
+                    'is this name legal? I hope it is',
+                    'some_file.pdf#',
+                    'some_file.pdf?',
+                    '?some_file.pdf',
+                    'some%file.pdf',
+                    'some%2Ffile.pdf',
+                    'some%22file.pdf',
+                    'some%20file.pdf',
+                    "G%C3%BCnter's%20file.pdf",
+                    'table%&?*2',
+                    'bar' // make sure we can go back to the original name as a last step
+                ];
+                eachPair(names, (from, to) => {
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains(`${from}`).rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input').type(`{selectall}{backspace}${to}`);
+                        });
+                    cy.get('[data-cy=form-submit-btn]').click();
+                    cy.get('[data-cy=collection-files-panel]')
+                        .should('not.contain', `${from}`)
+                        .and('contain', `${to}`);
+                })
+            });
     });
 
-    it('renames a file to a different directory', function() {
+    it('renames a file to a different directory', function () {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
             owner_uuid: activeUser.user.uuid,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
-        .as('testCollection').then(function() {
-            cy.loginAs(activeUser);
-            cy.doSearch(`${this.testCollection.uuid}`);
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection').then(function () {
+                cy.loginAs(activeUser);
+                cy.doSearch(`${this.testCollection.uuid}`);
 
-            // Rename 'bar' to 'subdir/foo'
-            cy.get('[data-cy=collection-files-panel]')
-                .contains('bar').rightclick();
-            cy.get('[data-cy=context-menu]')
-                .contains('Rename')
-                .click();
-            cy.get('[data-cy=form-dialog]')
-                .should('contain', 'Rename')
-                .within(() => {
-                    cy.get('input').type(`{selectall}{backspace}subdir/foo`);
-                });
-            cy.get('[data-cy=form-submit-btn]').click();
-            cy.get('[data-cy=collection-files-panel]')
-                .should('not.contain', 'bar')
-                .and('contain', 'subdir');
-            // Look for the "arrow icon" and expand the "subdir" directory.
-            cy.get('[data-cy=virtual-file-tree] > div > i').click();
-            // Rename 'subdir/foo' to 'baz'
-            cy.get('[data-cy=collection-files-panel]')
-                .contains('foo').rightclick();
-            cy.get('[data-cy=context-menu]')
-                .contains('Rename')
-                .click();
-            cy.get('[data-cy=form-dialog]')
-                .should('contain', 'Rename')
-                .within(() => {
-                    cy.get('input')
-                        .should('have.value', 'subdir/foo')
-                        .type(`{selectall}{backspace}baz`);
+                ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('bar').rightclick({force: true});
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
+                        });
+                    cy.get('[data-cy=form-submit-btn]').click();
+                    cy.get('[data-cy=collection-files-panel]')
+                        .should('not.contain', 'bar')
+                        .and('contain', subdir);
+                    // Look for the "arrow icon" and expand the "subdir" directory.
+                    cy.get('[data-cy=virtual-file-tree] > div > i').click();
+                    // Rename 'subdir/foo' to 'foo'
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('foo').rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input')
+                                .should('have.value', `${subdir}/foo`)
+                                .type(`{selectall}{backspace}bar`);
+                        });
+                    cy.get('[data-cy=form-submit-btn]').click();
+                    cy.get('[data-cy=collection-files-panel]')
+                        .should('contain', subdir) // empty dir kept
+                        .and('contain', 'bar');
+
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains(subdir).rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Remove')
+                        .click();
+                    cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
                 });
-            cy.get('[data-cy=form-submit-btn]').click();
-            cy.get('[data-cy=collection-files-panel]')
-                .should('contain', 'subdir') // empty dir kept
-                .and('contain', 'baz');
-        });
+            });
     });
 
-    it('tries to rename a file with illegal names', function() {
+    it('tries to rename a file with illegal names', function () {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
             owner_uuid: activeUser.user.uuid,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
-        .as('testCollection').then(function() {
-            cy.loginAs(activeUser);
-            cy.doSearch(`${this.testCollection.uuid}`);
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection').then(function () {
+                cy.loginAs(activeUser);
+                cy.doSearch(`${this.testCollection.uuid}`);
 
-            const illegalNamesFromUI = [
-                ['.', "Name cannot be '.' or '..'"],
-                ['..', "Name cannot be '.' or '..'"],
-                ['', 'This field is required'],
-                [' ', 'Leading/trailing whitespaces not allowed'],
-                [' foo', 'Leading/trailing whitespaces not allowed'],
-                ['foo ', 'Leading/trailing whitespaces not allowed'],
-                ['//foo', 'Empty dir name not allowed']
-            ]
-            illegalNamesFromUI.forEach(([name, errMsg]) => {
-                cy.get('[data-cy=collection-files-panel]')
-                    .contains('bar').rightclick();
-                cy.get('[data-cy=context-menu]')
-                    .contains('Rename')
-                    .click();
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.get('input').type(`{selectall}{backspace}${name}`);
-                    });
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.contains(`${errMsg}`);
-                    });
-                cy.get('[data-cy=form-cancel-btn]').click();
-            })
-        });
+                const illegalNamesFromUI = [
+                    ['.', "Name cannot be '.' or '..'"],
+                    ['..', "Name cannot be '.' or '..'"],
+                    ['', 'This field is required'],
+                    [' ', 'Leading/trailing whitespaces not allowed'],
+                    [' foo', 'Leading/trailing whitespaces not allowed'],
+                    ['foo ', 'Leading/trailing whitespaces not allowed'],
+                    ['//foo', 'Empty dir name not allowed']
+                ]
+                illegalNamesFromUI.forEach(([name, errMsg]) => {
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('bar').rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input').type(`{selectall}{backspace}${name}`);
+                        });
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.contains(`${errMsg}`);
+                        });
+                    cy.get('[data-cy=form-cancel-btn]').click();
+                })
+            });
     });
 
-    it('can correctly display old versions', function() {
+    it('can correctly display old versions', function () {
         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
         let colUuid = '';
         let oldVersionUuid = '';
@@ -303,50 +336,51 @@ describe('Collection panel tests', function() {
             filters: `[["name", "=", "${colName}"]]`,
             include_old_versions: true
         })
-        .its('body.items').as('collections')
-        .then(function() {
-            expect(this.collections).to.be.empty;
-        });
+            .its('body.items').as('collections')
+            .then(function () {
+                expect(this.collections).to.be.empty;
+            });
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
             name: colName,
             owner_uuid: activeUser.user.uuid,
             preserve_version: true,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
-        .as('originalVersion').then(function() {
-            // Change the file name to create a new version.
-            cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
-                manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
-            })
-            colUuid = this.originalVersion.uuid;
-        });
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('originalVersion').then(function () {
+                // Change the file name to create a new version.
+                cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
+                    manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
+                })
+                colUuid = this.originalVersion.uuid;
+            });
         // Confirm that there are 2 versions of the collection
         cy.doRequest('GET', '/arvados/v1/collections', null, {
             filters: `[["name", "=", "${colName}"]]`,
             include_old_versions: true
         })
-        .its('body.items').as('collections')
-        .then(function() {
-            expect(this.collections).to.have.lengthOf(2);
-            this.collections.map(function(aCollection) {
-                expect(aCollection.current_version_uuid).to.equal(colUuid);
-                if (aCollection.uuid !== aCollection.current_version_uuid) {
-                    oldVersionUuid = aCollection.uuid;
-                }
-            });
-            // Check the old version displays as what it is.
-            cy.loginAs(activeUser)
-            cy.doSearch(`${oldVersionUuid}`);
+            .its('body.items').as('collections')
+            .then(function () {
+                expect(this.collections).to.have.lengthOf(2);
+                this.collections.map(function (aCollection) {
+                    expect(aCollection.current_version_uuid).to.equal(colUuid);
+                    if (aCollection.uuid !== aCollection.current_version_uuid) {
+                        oldVersionUuid = aCollection.uuid;
+                    }
+                });
+                // Check the old version displays as what it is.
+                cy.loginAs(activeUser)
+                cy.doSearch(`${oldVersionUuid}`);
 
-            cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
-            cy.get('[data-cy=read-only-icon]').should('exist');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName);
-            cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
-        });
+                cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
+                cy.get('[data-cy=read-only-icon]').should('exist');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName);
+                cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
+            });
     });
 
-    it('uses the collection version browser to view a previous version', function() {
+    it('uses the collection version browser to view a previous version', function () {
         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
 
         // Creates the collection using the admin token so we can set up
@@ -355,125 +389,126 @@ describe('Collection panel tests', function() {
             name: colName,
             owner_uuid: activeUser.user.uuid,
             preserve_version: true,
-            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"})
-        .as('collection').then(function() {
-            // Visit collection, check basic information
-            cy.loginAs(activeUser)
-            cy.doSearch(`${this.collection.uuid}`);
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
+        })
+            .as('collection').then(function () {
+                // Visit collection, check basic information
+                cy.loginAs(activeUser)
+                cy.doSearch(`${this.collection.uuid}`);
 
-            cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
-            cy.get('[data-cy=read-only-icon]').should('not.exist');
-            cy.get('[data-cy=collection-version-number]').should('contain', '1');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName);
-            cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
+                cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
+                cy.get('[data-cy=read-only-icon]').should('not.exist');
+                cy.get('[data-cy=collection-version-number]').should('contain', '1');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName);
+                cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
 
-            // Modify collection, expect version number change
-            cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
-            cy.get('[data-cy=context-menu]').contains('Remove').click();
-            cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
-            cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
-            cy.get('[data-cy=collection-version-number]').should('contain', '2');
-            cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
+                // Modify collection, expect version number change
+                cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
+                cy.get('[data-cy=context-menu]').contains('Remove').click();
+                cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
+                cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+                cy.get('[data-cy=collection-version-number]').should('contain', '2');
+                cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
 
-            // Click on version number, check version browser. Click on past version.
-            cy.get('[data-cy=collection-version-browser]').should('not.exist');
-            cy.get('[data-cy=collection-version-number]').contains('2').click();
-            cy.get('[data-cy=collection-version-browser]')
-                .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
-                .within(() => {
-                    // Version 1: 6 bytes in size
-                    cy.get('[data-cy=collection-version-browser-select-1]')
-                        .should('contain', '1').and('contain', '6 B');
-                    // Version 2: 3 bytes in size (one file removed)
-                    cy.get('[data-cy=collection-version-browser-select-2]')
-                        .should('contain', '2').and('contain', '3 B');
-                    cy.get('[data-cy=collection-version-browser-select-3]')
-                        .should('not.exist');
-                    cy.get('[data-cy=collection-version-browser-select-1]')
-                        .click();
-            });
-            cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
-            cy.get('[data-cy=read-only-icon]').should('exist');
-            cy.get('[data-cy=collection-version-number]').should('contain', '1');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName);
-            cy.get('[data-cy=collection-files-panel]')
-                .should('contain', 'foo').and('contain', 'bar');
+                // Click on version number, check version browser. Click on past version.
+                cy.get('[data-cy=collection-version-browser]').should('not.exist');
+                cy.get('[data-cy=collection-version-number]').contains('2').click();
+                cy.get('[data-cy=collection-version-browser]')
+                    .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
+                    .within(() => {
+                        // Version 1: 6 bytes in size
+                        cy.get('[data-cy=collection-version-browser-select-1]')
+                            .should('contain', '1').and('contain', '6 B');
+                        // Version 2: 3 bytes in size (one file removed)
+                        cy.get('[data-cy=collection-version-browser-select-2]')
+                            .should('contain', '2').and('contain', '3 B');
+                        cy.get('[data-cy=collection-version-browser-select-3]')
+                            .should('not.exist');
+                        cy.get('[data-cy=collection-version-browser-select-1]')
+                            .click();
+                    });
+                cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
+                cy.get('[data-cy=read-only-icon]').should('exist');
+                cy.get('[data-cy=collection-version-number]').should('contain', '1');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName);
+                cy.get('[data-cy=collection-files-panel]')
+                    .should('contain', 'foo').and('contain', 'bar');
 
-            // Check that only old collection action are available on context menu
-            cy.get('[data-cy=collection-panel-options-btn]').click();
-            cy.get('[data-cy=context-menu]')
-                .should('contain', 'Restore version')
-                .and('not.contain', 'Add to favorites');
-            cy.get('body').click(); // Collapse the menu avoiding details panel expansion
+                // Check that only old collection action are available on context menu
+                cy.get('[data-cy=collection-panel-options-btn]').click();
+                cy.get('[data-cy=context-menu]')
+                    .should('contain', 'Restore version')
+                    .and('not.contain', 'Add to favorites');
+                cy.get('body').click(); // Collapse the menu avoiding details panel expansion
 
-            // Click on "head version" link, confirm that it's the latest version.
-            cy.get('[data-cy=collection-info-panel]').contains('head version').click();
-            cy.get('[data-cy=collection-info-panel]')
-                .should('not.contain', 'This is an old version');
-            cy.get('[data-cy=read-only-icon]').should('not.exist');
-            cy.get('[data-cy=collection-version-number]').should('contain', '2');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName);
-            cy.get('[data-cy=collection-files-panel]').
-                should('not.contain', 'foo').and('contain', 'bar');
+                // Click on "head version" link, confirm that it's the latest version.
+                cy.get('[data-cy=collection-info-panel]').contains('head version').click();
+                cy.get('[data-cy=collection-info-panel]')
+                    .should('not.contain', 'This is an old version');
+                cy.get('[data-cy=read-only-icon]').should('not.exist');
+                cy.get('[data-cy=collection-version-number]').should('contain', '2');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName);
+                cy.get('[data-cy=collection-files-panel]').
+                    should('not.contain', 'foo').and('contain', 'bar');
 
-            // Check that old collection action isn't available on context menu
-            cy.get('[data-cy=collection-panel-options-btn]').click()
-            cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
-            cy.get('body').click(); // Collapse the menu avoiding details panel expansion
+                // Check that old collection action isn't available on context menu
+                cy.get('[data-cy=collection-panel-options-btn]').click()
+                cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
+                cy.get('body').click(); // Collapse the menu avoiding details panel expansion
 
-            // Make another change, confirm new version.
-            cy.get('[data-cy=collection-panel-options-btn]').click();
-            cy.get('[data-cy=context-menu]').contains('Edit collection').click();
-            cy.get('[data-cy=form-dialog]')
-                .should('contain', 'Edit Collection')
-                .within(() => {
-                    // appends some text
-                    cy.get('input').first().type(' renamed');
-                });
-            cy.get('[data-cy=form-submit-btn]').click();
-            cy.get('[data-cy=collection-info-panel]')
-                .should('not.contain', 'This is an old version');
-            cy.get('[data-cy=read-only-icon]').should('not.exist');
-            cy.get('[data-cy=collection-version-number]').should('contain', '3');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
-            cy.get('[data-cy=collection-files-panel]')
-                .should('not.contain', 'foo').and('contain', 'bar');
-            cy.get('[data-cy=collection-version-browser-select-3]')
-                .should('contain', '3').and('contain', '3 B');
+                // Make another change, confirm new version.
+                cy.get('[data-cy=collection-panel-options-btn]').click();
+                cy.get('[data-cy=context-menu]').contains('Edit collection').click();
+                cy.get('[data-cy=form-dialog]')
+                    .should('contain', 'Edit Collection')
+                    .within(() => {
+                        // appends some text
+                        cy.get('input').first().type(' renamed');
+                    });
+                cy.get('[data-cy=form-submit-btn]').click();
+                cy.get('[data-cy=collection-info-panel]')
+                    .should('not.contain', 'This is an old version');
+                cy.get('[data-cy=read-only-icon]').should('not.exist');
+                cy.get('[data-cy=collection-version-number]').should('contain', '3');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
+                cy.get('[data-cy=collection-files-panel]')
+                    .should('not.contain', 'foo').and('contain', 'bar');
+                cy.get('[data-cy=collection-version-browser-select-3]')
+                    .should('contain', '3').and('contain', '3 B');
 
-            // Check context menus on version browser
-            cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
-            cy.get('[data-cy=context-menu]')
-                .should('contain', 'Add to favorites')
-                .and('contain', 'Make a copy')
-                .and('contain', 'Edit collection');
-            cy.get('body').click();
-            // (and now an old version...)
-            cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
-            cy.get('[data-cy=context-menu]')
-                .should('not.contain', 'Add to favorites')
-                .and('contain', 'Make a copy')
-                .and('not.contain', 'Edit collection');
-            cy.get('body').click();
+                // Check context menus on version browser
+                cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
+                cy.get('[data-cy=context-menu]')
+                    .should('contain', 'Add to favorites')
+                    .and('contain', 'Make a copy')
+                    .and('contain', 'Edit collection');
+                cy.get('body').click();
+                // (and now an old version...)
+                cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
+                cy.get('[data-cy=context-menu]')
+                    .should('not.contain', 'Add to favorites')
+                    .and('contain', 'Make a copy')
+                    .and('not.contain', 'Edit collection');
+                cy.get('body').click();
 
-            // Restore first version
-            cy.get('[data-cy=collection-version-browser]').within(() => {
-                cy.get('[data-cy=collection-version-browser-select-1]').click();
+                // Restore first version
+                cy.get('[data-cy=collection-version-browser]').within(() => {
+                    cy.get('[data-cy=collection-version-browser-select-1]').click();
+                });
+                cy.get('[data-cy=collection-panel-options-btn]').click()
+                cy.get('[data-cy=context-menu]').contains('Restore version').click();
+                cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
+                cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+                cy.get('[data-cy=collection-info-panel]')
+                    .should('not.contain', 'This is an old version');
+                cy.get('[data-cy=collection-version-number]').should('contain', '4');
+                cy.get('[data-cy=collection-info-panel]').should('contain', colName);
+                cy.get('[data-cy=collection-files-panel]')
+                    .should('contain', 'foo').and('contain', 'bar');
             });
-            cy.get('[data-cy=collection-panel-options-btn]').click()
-            cy.get('[data-cy=context-menu]').contains('Restore version').click();
-            cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
-            cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
-            cy.get('[data-cy=collection-info-panel]')
-                .should('not.contain', 'This is an old version');
-            cy.get('[data-cy=collection-version-number]').should('contain', '4');
-            cy.get('[data-cy=collection-info-panel]').should('contain', colName);
-            cy.get('[data-cy=collection-files-panel]')
-                .should('contain', 'foo').and('contain', 'bar');
-        });
     });
 
-    it('creates new collection on home project', function() {
+    it('creates new collection on home project', function () {
         cy.loginAs(activeUser);
         cy.doSearch(`${activeUser.user.uuid}`);
         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
diff --git a/src/common/url.test.ts b/src/common/url.test.ts
new file mode 100644 (file)
index 0000000..21bc518
--- /dev/null
@@ -0,0 +1,57 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { customDecodeURI, customEncodeURI } from './url';
+
+describe('url', () => {
+    describe('customDecodeURI', () => {
+        it('should decode encoded URI', () => {
+            // given
+            const path = 'test%23test%2Ftest';
+            const expectedResult = 'test#test%2Ftest';
+
+            // when
+            const result = customDecodeURI(path);
+
+            // 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 URI', () => {
+            // given
+            const path = 'test#test/test';
+            const expectedResult = 'test%23test/test';
+
+            // when
+            const result = customEncodeURI(path);
+
+            // 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 9789b65effb6b47d6ed14c0589cb39b2b032c2a4..185737cac331d2a6a5eece01e8f99f293f76c230 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 export function getUrlParameter(search: string, name: string) {
     const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
     const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
@@ -13,3 +17,19 @@ export function normalizeURLPath(url: string) {
     }
     return u.toString();
 }
+
+export const customEncodeURI = (path: string) => {
+    try {
+        return path.split('/').map(encodeURIComponent).join('/');
+    } catch(e) {}
+
+    return path;
+};
+
+export const customDecodeURI = (path: string) => {
+    try {
+        return path.split('%2F').map(decodeURIComponent).join('%2F');
+    } catch(e) {}
+
+    return path;
+};
index b928f82a0ff9e48a2968e335b9d8528ca0b09bf3..2ab106fcd3cb90a8710de2c0c5662cb8b53b78c5 100644 (file)
@@ -2,6 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { customEncodeURI } from "./url";
 import { WebDAV } from "./webdav";
 
 describe('WebDAV', () => {
@@ -54,70 +55,72 @@ describe('WebDAV', () => {
     it('COPY', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.copy('foo', 'foo-copy');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('COPY', 'foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'foo-copy');
+        expect(open).toHaveBeenCalledWith('COPY', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-copy');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
     it('COPY - adds baseURL with trailing slash to Destination header', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
-        webdav.defaults.baseURL = 'base/';
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.copy('foo', 'foo-copy');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('COPY', 'base/foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'base/foo-copy');
+        expect(open).toHaveBeenCalledWith('COPY', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-copy');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
     it('COPY - adds baseURL without trailing slash to Destination header', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
-        webdav.defaults.baseURL = 'base';
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.copy('foo', 'foo-copy');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('COPY', 'base/foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'base/foo-copy');
+        expect(open).toHaveBeenCalledWith('COPY', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-copy');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
     it('MOVE', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.move('foo', 'foo-moved');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('MOVE', 'foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'foo-moved');
+        expect(open).toHaveBeenCalledWith('MOVE', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-moved');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
     it('MOVE - adds baseURL with trailing slash to Destination header', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
-        webdav.defaults.baseURL = 'base/';
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.move('foo', 'foo-moved');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('MOVE', 'base/foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'base/foo-moved');
+        expect(open).toHaveBeenCalledWith('MOVE', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-moved');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
     it('MOVE - adds baseURL without trailing slash to Destination header', async () => {
         const { open, setRequestHeader, load, createRequest } = mockCreateRequest();
         const webdav = new WebDAV(undefined, createRequest);
-        webdav.defaults.baseURL = 'base';
+        webdav.defaults.baseURL = 'http://base';
         const promise = webdav.move('foo', 'foo-moved');
         load();
         const request = await promise;
-        expect(open).toHaveBeenCalledWith('MOVE', 'base/foo');
-        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'base/foo-moved');
+        expect(open).toHaveBeenCalledWith('MOVE', 'http://base/foo');
+        expect(setRequestHeader).toHaveBeenCalledWith('Destination', 'http://base/foo-moved');
         expect(request).toBeInstanceOf(XMLHttpRequest);
     });
 
index c4d8acaea2e8a58f090b21d6b4b8dc48a31c0e49..758a5e18e1e9ad44015b9a802d0e532e70ba3d76 100644 (file)
@@ -2,6 +2,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import { customEncodeURI } from "./url";
+
 export class WebDAV {
 
     defaults: WebDAVDefaults = {
@@ -75,7 +77,8 @@ export class WebDAV {
             r.open(config.method,
                 `${this.defaults.baseURL
                     ? this.defaults.baseURL+'/'
-                    : ''}${encodeURI(config.url)}`);
+                    : ''}${customEncodeURI(config.url)}`);
+
             const headers = { ...this.defaults.headers, ...config.headers };
             Object
                 .keys(headers)
index 3c6feb5dce8836a92a08074ba32a768af4ec84fc..e7db3acad8d904b58b4ae0c2061023eaade227b4 100644 (file)
@@ -2,9 +2,19 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string) => {
+import { customDecodeURI } from "./url";
+
+export const getTagValue = (document: Document | Element, tagName: string, defaultValue: string, skipDecoding: boolean = false) => {
     const [el] = Array.from(document.getElementsByTagName(tagName));
-    return decodeURI(el ? htmlDecode(el.innerHTML) : defaultValue);
+    const URI = el ? htmlDecode(el.innerHTML) : defaultValue;
+
+    if (!skipDecoding) {
+        try {
+            return customDecodeURI(URI);
+        } catch(e) {}
+    }
+
+    return URI;
 };
 
 const htmlDecode = (input: string) => {
index 52867a836cdab2b971ad00198f45f950af51c659..5eb23ba194dd6bbb27feac0a356bcd9a29641ac5 100644 (file)
@@ -188,7 +188,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);
diff --git a/src/services/collection-service/collection-service-files-response.test.ts b/src/services/collection-service/collection-service-files-response.test.ts
new file mode 100644 (file)
index 0000000..074aa5c
--- /dev/null
@@ -0,0 +1,103 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { CollectionFile } from '~/models/collection-file';
+import { getFileFullPath, extractFilesData } from './collection-service-files-response';
+
+describe('collection-service-files-response', () => {
+
+    describe('extractFilesData', () => {
+        it('should correctly decode URLs & file names', () => {
+            const testCases = [
+                // input URL, input display name, expected URL, expected name
+                ['table%201%202%203', 'table 1 2 3', 'table%201%202%203', 'table 1 2 3'],
+                ['table%25&amp;%3F%2A2', 'table%&amp;?*2', 'table%25&%3F%2A2', 'table%&?*2'],
+                ["G%C3%BCnter%27s%20file.pdf", "Günter&#39;s file.pdf", "G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf"],
+                ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter&#39;s%20file.pdf', "G%25C3%25BCnter%27s%2520file.pdf", "G%C3%BCnter's%20file.pdf"]
+            ];
+
+            testCases.forEach(([inputURL, inputDisplayName, expectedURL, expectedName]) => {
+                // given
+                const collUUID = 'xxxxx-zzzzz-vvvvvvvvvvvvvvv';
+                const xmlData = `
+                <?xml version="1.0" encoding="UTF-8"?>
+                <D:multistatus xmlns:D="DAV:">
+                    <D:response>
+                        <D:href>/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/</D:href>
+                        <D:propstat>
+                            <D:prop>
+                                <D:resourcetype>
+                                    <D:collection xmlns:D="DAV:"/>
+                                </D:resourcetype>
+                                <D:supportedlock>
+                                    <D:lockentry xmlns:D="DAV:">
+                                        <D:lockscope>
+                                            <D:exclusive/>
+                                        </D:lockscope>
+                                        <D:locktype>
+                                            <D:write/>
+                                        </D:locktype>
+                                    </D:lockentry>
+                                </D:supportedlock>
+                                <D:displayname></D:displayname>
+                                <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
+                            </D:prop>
+                            <D:status>HTTP/1.1 200 OK</D:status>
+                        </D:propstat>
+                    </D:response>
+                    <D:response>
+                        <D:href>/c=${collUUID}/${inputURL}</D:href>
+                        <D:propstat>
+                            <D:prop>
+                                <D:resourcetype></D:resourcetype>
+                                <D:getcontenttype>application/pdf</D:getcontenttype>
+                                <D:supportedlock>
+                                    <D:lockentry xmlns:D="DAV:">
+                                        <D:lockscope>
+                                            <D:exclusive/>
+                                        </D:lockscope>
+                                        <D:locktype>
+                                            <D:write/>
+                                        </D:locktype>
+                                    </D:lockentry>
+                                </D:supportedlock>
+                                <D:displayname>${inputDisplayName}</D:displayname>
+                                <D:getcontentlength>3</D:getcontentlength>
+                                <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
+                                <D:getetag>"166feb9c9110c008325a59"</D:getetag>
+                            </D:prop>
+                            <D:status>HTTP/1.1 200 OK</D:status>
+                        </D:propstat>
+                    </D:response>
+                </D:multistatus>
+                `;
+                const parser = new DOMParser();
+                const xmlDoc = parser.parseFromString(xmlData, "text/xml");
+
+                // when
+                const result = extractFilesData(xmlDoc);
+
+                // then
+                expect(result).toEqual([{ id: `${collUUID}/${expectedName}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]);
+            });
+        });
+    });
+
+    describe('getFileFullPath', () => {
+        it('should encode weird names', async () => {
+            // given
+            const file = {
+                name: '#test',
+                path: 'http://localhost',
+            } as CollectionFile;
+
+            // when
+            const result = getFileFullPath(file);
+
+            // then
+            expect(result).toBe('http://localhost/#test');
+        });
+
+    });
+});
\ No newline at end of file
index 5e6f7b83f0ecf7628546ce5101dd75c7e52f6629..325339d00bb803d6e8aebbd19e8926f3953b56e0 100644 (file)
@@ -25,33 +25,39 @@ export const extractFilesData = (document: Document) => {
         .from(document.getElementsByTagName('D:response'))
         .slice(1) // omit first element which is collection itself
         .map(element => {
-            const name = getTagValue(element, 'D:displayname', '');
-            const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
-            const url = getTagValue(element, 'D:href', '');
-            const nameSuffix = `/${name || ''}`;
+            const name = getTagValue(element, 'D:displayname', '', true); // skip decoding as value should be already decoded
+            const size = parseInt(getTagValue(element, 'D:getcontentlength', '0', true), 10);
+            const url = getTagValue(element, 'D:href', '', true);
             const collectionUuidMatch = collectionUrlPrefix.exec(url);
             const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';
-            const directory = url
+            const pathArray = url.split(`/`);
+            if (!pathArray.pop()) {
+                pathArray.pop();
+            }
+            const directory = pathArray.join('/')
                 .replace(collectionUrlPrefix, '')
-                .replace(nameSuffix, '');
+                .replace(/\/\//g, '/');
 
             const parentPath = directory.replace(/\/$/, '');
             const data = {
                 url,
                 id: [
                     collectionUuid ? collectionUuid : '',
-                    directory ? parentPath : '',
+                    directory ? unescape(parentPath) : '',
                     '/' + name
                 ].join(''),
                 name,
-                path: parentPath,
+                path: unescape(parentPath),
             };
 
-            return getTagValue(element, 'D:resourcetype', '')
+            const result = getTagValue(element, 'D:resourcetype', '')
                 ? createCollectionDirectory(data)
                 : createCollectionFile({ ...data, size });
+
+            return result;
         });
 };
 
-export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) =>
-    `${path}/${name}`;
+export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) => {
+    return `${path}/${name}`;
+};
\ No newline at end of file
index c46c3e27764470f1c214cc4ff82200d612b6a8c4..9fd8a13511ff850b26f9a40af01336616c2340e2 100644 (file)
@@ -10,6 +10,7 @@ import { AuthService } from "../auth-service/auth-service";
 import { extractFilesData } from "./collection-service-files-response";
 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
 import { ApiActions } from "~/services/api/api-actions";
+import { customEncodeURI } from "~/common/url";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -78,7 +79,7 @@ export class CollectionService extends TrashableResourceService<CollectionResour
     async moveFile(collectionUuid: string, oldPath: string, newPath: string) {
         await this.webdavClient.move(
             `c=${collectionUuid}${oldPath}`,
-            `c=${collectionUuid}${encodeURI(newPath)}`
+            `c=${collectionUuid}/${customEncodeURI(newPath)}`
         );
         await this.update(collectionUuid, { preserveVersion: true });
     }