added regex check on url input

This commit is contained in:
Sherry Ma 2020-03-07 23:04:37 -05:00 committed by Martin D Kealey
parent 826ecf0b8b
commit 40adf459bd

View file

@ -1868,23 +1868,36 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
async _addSite() { async _addSite() {
const formValues = new FormData(this._editForm); const formValues = new FormData(this._editForm);
console.log(formValues.get("container-id"));
console.log(formValues.get("site-name"));
const url = formValues.get("site-name"); const url = formValues.get("site-name");
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;
try { const fullURL = this.checkurl(url);
await browser.runtime.sendMessage({ Logic.setOrRemoveAssignment(tabId, fullURL, userContextId, false);
method: "setOrRemoveAssignment", },
tabId: tabId,
url: url, checkurl(url){
userContextId: userContextId, // append "https://" if protocol not found
value: false const regexWww = /.*www\..*/g;
}); const foundWww = url.match(regexWww);
} catch (e) { const regexhttp = /^http:\/\/.*/g;
console.log(e); const regexhttps = /^https:\/\/.*/g;
const foundhttp = url.match(regexhttp);
const foundhttps = url.match(regexhttps);
let newURL = url;
if (!foundhttp && !foundhttps) {
newURL = "https://" + url;
} }
if (!foundWww) {
if (newURL.match(regexhttp)) {
newURL = "http://www." + newURL.substring(7);
} else if (newURL.match(regexhttps)) {
newURL = "https://www." + newURL.substring(8);
}
}
return newURL;
}, },
showAssignedContainers(assignments) { showAssignedContainers(assignments) {