Skip to content

Commit

Permalink
Fix 2749 search urls for cross layer filter are compared ignoring "di…
Browse files Browse the repository at this point in the history
…rty" chars (#4004)

* Fix 2749 search urls for cross layer filter are compared ignoring "dirty" url

* fix test and check for dirty chars
  • Loading branch information
MV88 authored and Tobia Di Pisa committed Jul 25, 2019
1 parent 03c6aa4 commit e93bb16
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
20 changes: 12 additions & 8 deletions web/client/utils/URLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* LICENSE file in the root directory of this source tree.
*/

const urlParts = (url) => {
import Url from "url";

export const urlParts = (url) => {
if (!url) return {};
let isRelativeUrl = !(url.indexOf("http") === 0);
let urlPartsArray = isRelativeUrl ? [] : url.match(/([^:]*:)\/\/([^:]*:?[^@]*@)?([^:\/\?]*):?([^\/\?]*)/);
Expand All @@ -32,19 +34,21 @@ const urlParts = (url) => {
* @param {string} otherUrl url to compare to
* @return {boolean} true when urls are the same else false
*/
const isSameUrl = (originalUrl, otherUrl) => {
export const isSameUrl = (originalUrl, otherUrl) => {
if (originalUrl === otherUrl) return true;
const urlParsed = Url.parse(originalUrl);
const otherUrlParsed = Url.parse(otherUrl);
const originalUrlParts = urlParts(originalUrl);
const otherUrlParts = urlParts(otherUrl);
const isSameProtocol = originalUrlParts.protocol === otherUrlParts.protocol;
const isSameDomain = originalUrlParts.domain === otherUrlParts.domain;
const isSameRootPath = originalUrlParts.rootPath === otherUrlParts.rootPath;
const isSamePort = originalUrlParts.port === otherUrlParts.port;
return isSameProtocol && isSamePort && isSameDomain && isSameRootPath;
};


module.exports = {
isSameUrl,
urlParts
const isSamePathname = urlParsed.pathname === otherUrlParsed.pathname;
const ignoreSearchPath = ((urlParsed.search || "").length < 4 ) === (otherUrlParsed.search || "").length < 4;
/* ignoreSearchPath is needed to ignore url where path are dirty like /wfs? and /wfs?&
* the minimum valid search path is 4 char length => ?p=v
*/
return isSameProtocol && isSamePort && isSameDomain && (ignoreSearchPath && isSamePathname ? true : isSameRootPath);
};
28 changes: 28 additions & 0 deletions web/client/utils/__tests__/URLUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,33 @@ describe('URLUtils', () => {
const data = isSameUrl(url3, url4);
expect(data).toBeTruthy();
});
it('test isSameUrl with clean and dirty relative url', () => {
expect(isSameUrl(
"/geoserver/wfs",
"/geoserver/wfs?&")).toBe(true);
expect(isSameUrl(
"/geoserver/wfs",
"/geoserver/wfs?")).toBe(true);
expect(isSameUrl(
"/geoserver/wfs?&",
"/geoserver/wfs?param1=true&param2=false")).toBe(false);
expect(isSameUrl(
"/path/geoserver/wfs?",
"/geoserver/wfs?")).toBe(false);
});
it('test isSameUrl with clean and dirty absolute url', () => {
expect(isSameUrl(
"https://demo.geo-solutions.it:443/geoserver/wfs",
"https://demo.geo-solutions.it/geoserver/wfs?")).toBe(true);
expect(isSameUrl(
"https://demo.geo-solutions.it:443/geoserver/wfs",
"https://demo.geo-solutions.it/geoserver/wfs?")).toBe(true);
expect(isSameUrl(
"https://demo.geo-solutions.it/geoserver/wfs?",
"https://demo.geo-solutions.it/geoserver/wfs?param1=true&param2=false")).toBe(false);
expect(isSameUrl(
"https://demo.geo-solutions.it/path/geoserver/wfs?",
"https://demo.geo-solutions.it/geoserver/wfs?")).toBe(false);
});

});

0 comments on commit e93bb16

Please sign in to comment.