From e6f9ce7437d8f83076680391be0d260f80a018c3 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 22 Dec 2020 18:32:08 -0800 Subject: fixup ancestor algorithm so extensions/ appears --- extension/background.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'extension') diff --git a/extension/background.js b/extension/background.js index ee3976e..4fb5923 100644 --- a/extension/background.js +++ b/extension/background.js @@ -339,15 +339,15 @@ for (let key in router) { if (path == '') path = '/'; if (!router[path]) { + function depth(p) { return p === '/' ? 0 : (p.match(/\//g) || []).length; } + // find all direct children - let children = Object.keys(router) - .filter(k => k.startsWith(path) && - (k.match(/\//g) || []).length === - (path.match(/\//g) || []).length + 1) - .map(k => k.substr((path === '/' ? 0 : path.length) + 1).split('/')[0]); - children = [".", "..", ...new Set(children)]; - - router[path] = { readdir() { return { entries: children }; } }; + let entries = Object.keys(router) + .filter(k => k.startsWith(path) && depth(k) === depth(path) + 1) + .map(k => k.substr((path === '/' ? 0 : path.length) + 1).split('/')[0]); + entries = [".", "..", ...new Set(entries)]; + + router[path] = { readdir() { return { entries }; } }; } } } @@ -355,8 +355,8 @@ if (TESTING) { // I wish I could color this section with... a pink background, o const assert = require('assert'); (async () => { assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url', 'title', 'text', 'screenshot.png', 'resources', 'scripts', 'control'] }); - assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'tabs', 'extensions'] }); - assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'by-id', 'by-title'] }); + assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'extensions', 'tabs'] }); + assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'create', 'by-id', 'by-title', 'last-focused'] }); assert.deepEqual(findRoute('/tabs/by-id/TABID/url'), router['/tabs/by-id/*/url']); })() -- cgit v1.2.3