diff --git a/keepassxc-browser/global.js b/keepassxc-browser/global.js index 8e1d970..23cbd06 100755 --- a/keepassxc-browser/global.js +++ b/keepassxc-browser/global.js @@ -4,6 +4,10 @@ const IGNORE_NOTHING = 'ignoreNothing'; const IGNORE_NORMAL = 'ignoreNormal'; const IGNORE_FULL = 'ignoreFull'; +var schemeSegment = '(\\*|http|https|ws|wss|file|ftp)'; +var hostSegment = '(\\*|(?:\\*\\.)?(?:[^/*]+))?'; +var pathSegment = '(.*)'; + var isFirefox = function() { if (!(/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor))) { return true; @@ -35,21 +39,18 @@ var matchPatternToRegExp = function(pattern) { return (/^(?:http|https|file|ftp|app):\/\//); } - const schemeSegment = '(\\*|http|https|ws|wss|file|ftp)'; - const hostSegment = '(\\*|(?:\\*\\.)?(?:[^/*]+))?'; - const pathSegment = '(.*)'; const matchPatternRegExp = new RegExp( `^${schemeSegment}://${hostSegment}/${pathSegment}$` ); let match = matchPatternRegExp.exec(pattern); if (!match) { - throw new TypeError('"${pattern}" is not a valid MatchPattern'); + throw new TypeError(pattern + ' is not a valid MatchPattern'); } let [, scheme, host, path] = match; if (!host) { - throw new TypeError('"${pattern}" does not have a valid host'); + throw new TypeError(pattern + ' does not have a valid host'); } let regex = '^'; diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index c1c1897..58e582b 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -299,7 +299,7 @@ options.initSitePreferences = function() { $('#sitePreferencesManualAdd').click(function(e) { e.preventDefault(); - const value = $('#manualUrl').val(); + let value = $('#manualUrl').val(); if (value.length > 10 && value.length <= 2000) { if (options.settings['sitePreferences'] === undefined) { options.settings['sitePreferences'] = []; @@ -309,6 +309,11 @@ options.initSitePreferences = function() { const trClone = $('#tab-site-preferences table tr.clone:first').clone(true); trClone.removeClass('clone'); + // Fills the last / char if needed. This ensures the compatibility with Match Patterns + if (options.slashNeededForUrl(value)) { + value += '/'; + } + const tr = trClone.clone(true); tr.data('url', value); tr.attr('id', 'tr-scf' + newValue); @@ -387,3 +392,9 @@ options.initAbout = function() { $('#default-pass-shortcut').show(); } }; + +// Checks if URL has only scheme and host without the last / char. +options.slashNeededForUrl = function(pattern) { + const matchPattern = new RegExp(`^${schemeSegment}://${hostSegment}$`); + return matchPattern.exec(pattern); +};