From bf082617fc770c319fd7dc5f757ff53f9f6f4f9a Mon Sep 17 00:00:00 2001 From: CasVT Date: Fri, 28 Jul 2023 14:15:15 +0200 Subject: [PATCH] Added regex checks in URL builder (#3) --- frontend/static/js/notification.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/static/js/notification.js b/frontend/static/js/notification.js index 7fb218d..76d823f 100644 --- a/frontend/static/js/notification.js +++ b/frontend/static/js/notification.js @@ -508,7 +508,8 @@ function buildAppriseURL() { }) .filter(el => el !== null) .join('&') - template += (template.includes('?') ? '&' : '?') + args; + if (args) + template += (template.includes('?') ? '&' : '?') + args; template = template.replaceAll(' ', '%20'); console.debug(matching_templates); @@ -519,6 +520,24 @@ function buildAppriseURL() { function addService() { const add_button = document.querySelector('#add-service-window > .options > button[type="submit"]'); + + // Check regexes for input's + [...document.querySelectorAll('#add-service-window > input:not([data-regex=""])[data-regex]')] + .forEach(el => el.classList.remove('error-input')); + + const faulty_inputs = + [...document.querySelectorAll('#add-service-window > input:not([data-regex=""])[data-regex]')] + .filter(el => !new RegExp + ( + el.dataset.regex.split('').reverse().join('').split(',').slice(1).join(',').split('').reverse().join(''), + el.dataset.regex.split('').reverse().join('').split(',')[0] + ).test(el.value) + ); + if (faulty_inputs.length > 0) { + faulty_inputs.forEach(el => el.classList.add('error-input')); + return; + }; + const data = { 'title': document.querySelector('#service-title').value, 'url': buildAppriseURL()