From 7505096dda9b9d0add901c5189ec992720c4e674 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 14 Sep 2022 03:16:26 +0300 Subject: [PATCH] reworked path pattern matching... Signed-off-by: Alex A. Naanou --- pwiki/store/base.js | 43 +++++++++++++++++++++++++++---------------- pwiki2.js | 5 ----- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 8cc427c..e0a406c 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -334,16 +334,17 @@ module.BaseStore = { args = pwpath.joinArgs('', args) // NOTE: we are matching full paths only here so leading and // trainling '/' are optional... - // NOTE: we ensure that we match full names and always split - // at '/' only... - var pattern = new RegExp(`^\\/?${ - path - .replace(/^\/|\/$/g, '') - .replace(/\//g, '\\/') - //.replace(/\*\*/g, '.*') - .replace(/([\\\/]?)\*\*/g, '($1.*)') - .replace(/(?<=^|[\\\/]+|[^.])\*/g, '[^\\/]*') - }(?=[\\\\\/]|$)`) + var pattern = new RegExp(`^\\/?` + +RegExp.quoteRegExp( + // remove leading/trailing '/' + path.replace(/^\/|\/$/g, '')) + // pattern: ** + .replace(/\\\*\\\*/g, '(.*)') + // pattern: * + // NOTE: we are prepping the leading '.' of a pattern + // dir for hidden tests... + .replace(/(^|\\\/+)(\\\.|)([^\/]*)\\\*/g, '$1$2($3[^\\/]*)') + +'(?=[\\/]|$)', 'g') /*/ XXX CACHED.... var name = pwpath.basename(path) return [...(name.includes('*') ? @@ -359,14 +360,24 @@ module.BaseStore = { // skip metadata paths... if(p.includes('*')){ return res } - /*/ XXX HIDE this is wrong -- need to check for - // hidden paths within the match... - if(pwpath.basename(p)[0] == '.' - && !all){ - return res } - //*/ + // XXX HIDE + var m = [...p.matchAll(pattern)] + m.length > 0 + && (!all ? + // test if we need to hide things.... + m.reduce(function(res, m){ + return res === false ? + res + // XXX if we are using a partial pattern this is wrong... + // i.e. something like 'x*' (TEST) + : !/(^\.|[\\\/]\.)/.test(m[1]) + }, true) + : true) + && (m = m[0]) + /*/ var m = p.match(pattern) m + //*/ && (!strict || m[0] == p) && res.add( diff --git a/pwiki2.js b/pwiki2.js index be89185..6f70e59 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,11 +1,6 @@ /********************************************************************** * * -* XXX BUG: .hide_paths: -* - hidden dir should hide all the children -- BROKEN -* (see /.hidden/suppage) -* - listing a hidden subtree should work regardless of :all -- BROKEN -* (see: /.hidden/tree) * XXX might also be a good idea to investigate a .tree directory index * as a supplement to .paths() * XXX BUG: changing the URL does not start the spinner...