Only save protocol://domain from any given URL
This commit is contained in:
parent
1ac0fb2ab4
commit
66e21b5cfa
1 changed files with 37 additions and 18 deletions
|
@ -1873,11 +1873,11 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
const userContextId = formValues.get("container-id");
|
const userContextId = formValues.get("container-id");
|
||||||
const currentTab = await Logic.currentTab();
|
const currentTab = await Logic.currentTab();
|
||||||
const tabId = currentTab.id;
|
const tabId = currentTab.id;
|
||||||
const fullURL = this.checkUrl(url);
|
const baseURL = this.normalizeUrl(url);
|
||||||
|
|
||||||
if (fullURL !== null) {
|
if (baseURL !== null) {
|
||||||
// Assign URL to container
|
// Assign URL to container
|
||||||
await Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false);
|
await Logic.setOrRemoveAssignment(tabId, baseURL, userContextId, false);
|
||||||
|
|
||||||
// Clear form
|
// Clear form
|
||||||
document.querySelector("#edit-container-panel-site-input").value = "";
|
document.querySelector("#edit-container-panel-site-input").value = "";
|
||||||
|
@ -1888,25 +1888,44 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
checkUrl(url){
|
normalizeUrl(url){
|
||||||
const validUrl = /[\w.-]+(?:\.[\w.-]+)/g;
|
/*
|
||||||
const regexProtocol = /^https?:\/\/.*/g;
|
* Important: the rules that automatically open a site in a container only
|
||||||
const valid = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w\-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\\w]*))?)/g;
|
* look at the URL up to but excluding the / after the domainname.
|
||||||
let newURL = url;
|
*
|
||||||
|
* Furthermore, containers are only useful for http & https URLs because
|
||||||
|
* those are the only protocols that transmit cookies to maintain
|
||||||
|
* sessions.
|
||||||
|
*/
|
||||||
|
|
||||||
if (!url.match(validUrl)) {
|
// Preface with "https://" if no protocol present
|
||||||
return null;
|
const startsWithProtocol = /^\w+:\/\/|^mailto:/; // all protocols are followed by :// (except mailto)
|
||||||
|
if (!url.match(startsWithProtocol)) {
|
||||||
|
url = "https://" + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// append "https://" if protocol not found
|
/*
|
||||||
if (!url.match(regexProtocol)) {
|
* Dual-purpose match: (1) check that url start with http or https proto,
|
||||||
newURL = "https://" + url;
|
* and (2) exclude everything from the / after the domain (any path, any
|
||||||
}
|
* query string, and any anchor)
|
||||||
|
*/
|
||||||
|
const basePart = /^(https?:\/\/)([^/?#]*)/;
|
||||||
|
const r = url.match(basePart);
|
||||||
|
if (!r) return null;
|
||||||
|
const urlProto = r[1]; // includes :// if any
|
||||||
|
const urlConnection = r[2]; // [user[:passwd]@]domain[:port]
|
||||||
|
|
||||||
if (!newURL.match(valid)) {
|
// Extract domain from [user[:passwd]@]domain[:port]
|
||||||
return null;
|
const domainPart = /^(?:.*@)?([^:]+)/;
|
||||||
}
|
const d = urlConnection.match(domainPart);
|
||||||
return newURL;
|
if (!d) return null;
|
||||||
|
const urlDomain = d[1];
|
||||||
|
|
||||||
|
// Check that the domain is valid (RFC-1034)
|
||||||
|
const validDomain = /^(?:\w(?:[\w-]*\w)?)(?:\.\w(?:[\w-]*\w)?)+$/;
|
||||||
|
if (!urlDomain.match(validDomain)) return null;
|
||||||
|
|
||||||
|
return urlProto+urlDomain;
|
||||||
},
|
},
|
||||||
|
|
||||||
showAssignedContainers(assignments) {
|
showAssignedContainers(assignments) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue