Skip to content

Commit

Permalink
#6127 fixed regression for URLs without FQDN (#6855)
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed May 12, 2021
1 parent 3da7ed6 commit 05fe801
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions web/client/components/catalog/editor/MainForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import InfoPopover from '../../widgets/widget/InfoPopover';
import { FormControl as FC, Form, Col, FormGroup, ControlLabel, Alert } from "react-bootstrap";

import localizedProps from '../../misc/enhancers/localizedProps';
import {defaultPlaceholder, isHttps} from "./MainFormUtils";
import {defaultPlaceholder, isValidURL} from "./MainFormUtils";

const FormControl = localizedProps('placeholder')(FC);

Expand Down Expand Up @@ -129,7 +129,7 @@ export default ({
function handleProtocolValidity(url) {
onChangeUrl(url);
if (url) {
const isInvalidProtocol = !isHttps(url);
const isInvalidProtocol = !isValidURL(url);
setInvalidProtocol(isInvalidProtocol);
setValid(!isInvalidProtocol);
}
Expand Down
12 changes: 9 additions & 3 deletions web/client/components/catalog/editor/MainFormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export const defaultPlaceholder = (service) => {
return true;
};

export const isHttps = (catalogUrl = '') => {
const { protocol: mapStoreProtocol } = url.parse(window.location.href);
/**
* Check if the URL typed is valid or not
* @param {string} catalogUrl The URL of the catalog
* @param {string} currentLocation The current location, by default `window.location.href`
* @returns {boolean} true if the URL is valid
*/
export const isValidURL = (catalogUrl = '', currentLocation) => {
const { protocol: mapStoreProtocol } = url.parse(currentLocation ?? window.location.href);
const { protocol: catalogProtocol } = url.parse(catalogUrl);
if (mapStoreProtocol === 'https:') {
if (mapStoreProtocol === 'https:' && !!catalogProtocol) {
return mapStoreProtocol === catalogProtocol;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import expect from "expect";

import { isValidURL } from '../MainFormUtils';

describe('Catalog Main Form Editor Utils', () => {
it('isValidURL', () => {
const URLS = [
// http
['http://myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', false],
['http://myDomain.com/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
// https
['https://myDomain.com/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
['https://myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true],
// protocol relative URL
['//myDomain.com/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
['//myDomain.com/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true],
// absolute path
['/geoserver/wms', 'http://myMapStore.com/geoserver/wms', true],
['/geoserver/wms', 'https://myMapStore.com/geoserver/wms', true],
// relative path
["geoserver/wms", "http://myMapStore.com/geoserver/wms", true],
["geoserver/wms", "https://myMapStore.com/geoserver/wms", true]


];
URLS.forEach(([catalogURL, locationURL, valid]) => {
const result = isValidURL(catalogURL, locationURL);
expect(!!result).toEqual(!!valid, `${catalogURL} - added when location is ${locationURL} should be ${valid}, but it is ${result}`);
});
});
});

0 comments on commit 05fe801

Please sign in to comment.