mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Match patterns fix
This commit is contained in:
parent
cc7138c45d
commit
2bfcb7330c
2 changed files with 18 additions and 6 deletions
|
|
@ -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 = '^';
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue