diff --git a/ursh/indico_ursh/client/index.js b/ursh/indico_ursh/client/index.js index 622bf9f..d8f8135 100644 --- a/ursh/indico_ursh/client/index.js +++ b/ursh/indico_ursh/client/index.js @@ -15,7 +15,6 @@ * along with Indico; if not, see . */ -import 'url-polyfill'; import {handleAxiosError, indicoAxios} from 'indico/utils/axios'; @@ -38,7 +37,7 @@ async function _makeUrshRequest(originalURL) { function _validateAndFormatURL(url) { const $t = $T.domain('ursh'); if (!url) { - throw $t.gettext('Please fill in a URL to shorten'); + throw Error($t.gettext('Please fill in a URL to shorten')); } // if protocol is missing, prepend it @@ -46,18 +45,24 @@ function _validateAndFormatURL(url) { url = `${location.protocol}//${url}`; } - let parsedURL; - try { - parsedURL = new URL(url); - } catch (err) { - throw $t.gettext('This does not look like a valid URL'); + // regular expression, because I.E. does not like the URL class + const re = RegExp(`^(.+:)//([^/]+)(/.*)?$`); + const urlTokens = url.match(re); + if (!urlTokens) { + throw Error($t.gettext('This does not look like a valid URL')); } - parsedURL.protocol = location.protocol; // patch protocol to match server - if (parsedURL.hostname !== location.hostname) { - throw $t.gettext('Invalid host: only Indico URLs are allowed'); + // extract tokens + let protocol = urlTokens[1]; + const hostname = urlTokens[2]; + const path = urlTokens[3] ? urlTokens[3] : '/'; + + protocol = location.protocol; // patch protocol to match server + if (hostname !== location.hostname) { + throw Error($t.gettext('Invalid host: only Indico URLs are allowed')); } - return parsedURL.href; + + return `${protocol}//${hostname}${path}`; } function _getUrshInput() { @@ -86,7 +91,7 @@ function _getUrshInput() { input.val(formattedURL); return formattedURL; } catch (err) { - tip(err); + tip(err.message); input.focus().select(); return null; } diff --git a/ursh/package.json b/ursh/package.json deleted file mode 100644 index 68e321b..0000000 --- a/ursh/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "indico-plugin-ursh", - "version": "1.0.0", - "description": "URL shortening service provider for Indico", - "main": "indico_ursh/client/index.js", - "repository": { - "type": "git", - "url": "git+https://github.com/indico/indico-plugins.git" - }, - "author": "Indico Team ", - "license": "GPL-3.0", - "bugs": { - "url": "https://github.com/indico/indico-plugins/issues" - }, - "homepage": "https://github.com/indico/indico-plugins#readme", - "dependencies": { - "url-polyfill": "^1.1.0" - } -}