diff --git a/cypress/e2e/origin-search.cy.js b/cypress/e2e/origin-search.cy.js --- a/cypress/e2e/origin-search.cy.js +++ b/cypress/e2e/origin-search.cy.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2019-2021 The Software Heritage developers + * Copyright (C) 2019-2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -311,6 +311,30 @@ } }); + it('should encode origin argument in latest visit URL queried by XHR', function() { + // origin added in tests data by Python + const originUrl = 'https://example.org/project/download.php?version=2.0'; + cy.intercept(`**/api/1/origin/${encodeURIComponent(originUrl)}/visit/latest/**`) + .as('checkOriginVisit'); + + doSearch(originUrl); + + cy.wait('@checkOriginVisit'); + + cy.get('.swh-search-result-entry') + .should('have.length', 1); + + cy.get('.swh-search-result-entry#origin-0 .swh-origin-visit-type') + .should('have.text', 'tar'); + + cy.get('.swh-search-result-entry#origin-0 td a') + .should('have.text', originUrl); + + cy.get('.swh-search-result-entry#origin-0 .swh-visit-status') + .should('have.text', 'Archived'); + + }); + context('Test pagination', function() { it('should not paginate if there are not many results', function() { // Setup search diff --git a/swh/web/browse/assets/browse/origin-search.js b/swh/web/browse/assets/browse/origin-search.js --- a/swh/web/browse/assets/browse/origin-search.js +++ b/swh/web/browse/assets/browse/origin-search.js @@ -1,11 +1,11 @@ /** - * Copyright (C) 2018-2021 The Software Heritage developers + * Copyright (C) 2018-2022 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information */ -import {handleFetchError, errorMessageFromResponse, isArchivedOrigin} from 'utils/functions'; +import {errorMessageFromResponse, handleFetchError, isArchivedOrigin} from 'utils/functions'; const limit = 100; const linksPrev = []; @@ -53,7 +53,7 @@ tableRow += ''; table.append(tableRow); // get async latest visit snapshot and update visit status icon - let latestSnapshotUrl = Urls.api_1_origin_visit_latest(origin.url); + let latestSnapshotUrl = Urls.api_1_origin_visit_latest(encodeURIComponent(origin.url)); latestSnapshotUrl += '?require_snapshot=true'; promises.push(fetch(latestSnapshotUrl)); } diff --git a/swh/web/tests/data.py b/swh/web/tests/data.py --- a/swh/web/tests/data.py +++ b/swh/web/tests/data.py @@ -270,6 +270,15 @@ visit_type="tar", ) + # origin used in cypress test for origins search + _add_origin( + storage, + search, + counters, + origin_url="https://example.org/project/download.php?version=2.0", + visit_type="tar", + ) + sha1s: Set[Sha1] = set() directories = set() revisions = set()