Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 76b3b73

Browse files
committed
fix for buggy cd /history
Fixes #417 disallow cd / Fixes #416
1 parent c0e555d commit 76b3b73

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

app/content/js/command-tree.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const CDHelpers = {
9595
route = `/${A.join('/')}`,
9696
m = match(A, true) // make sure the context exists
9797

98+
debug('cd', m)
9899
if (!m || !m.children || (m.route !== route && !m.children[A[A.length - 1]])) {
99100
// maybe we need to load a plugin?
100101
if (!noRetry) {
@@ -104,7 +105,11 @@ const CDHelpers = {
104105
// then the desiredContext does not exist; the caller will handle error reporting
105106
return false
106107
}
107-
} else {
108+
} else if (m.route !== '/' && (!m.$ || m.options.subtreeHandler)) {
109+
// disallow cd /
110+
// and: m.$ means that there is a command installed here, so disallow cd'ing;
111+
// so: m.$ && m.options.subtreeHandler means that we installed this as a help handler below
112+
108113
// if the user expressed a synonym, use the main name
109114
if (m.options && m.options.synonymFor) {
110115
return exports.changeContext(m.options.synonymFor.route)()
@@ -305,8 +310,8 @@ exports.subtree = (route, options) => {
305310
//
306311
// also listen route e.g. /wsk, and present usage
307312
//
308-
listen(route, help, Object.assign({}, options, { noArgs: true }))
309-
listen(`${route}/help`, help, Object.assign({}, options, { noArgs: true }))
313+
listen(route, help, Object.assign({}, options, { noArgs: true, subtreeHandler: true }))
314+
listen(`${route}/help`, help, Object.assign({}, options, { noArgs: true, subtreeHandler: true }))
310315

311316
return leaf
312317
}

tests/tests/passes/02/cd.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ describe('Change contexts via cd', function() {
5858
doSwitch('..', '/wsk')
5959
doSwitch('./actions', '/wsk/actions')
6060
doSwitch('..', '/wsk')
61-
doSwitch('..', '/')
61+
//doSwitch('..', '/')
6262
doSwitch('/wsk/triggers', '/wsk/triggers')
6363

64+
bogusSwitch('/') // disallow switching to /
65+
bogusSwitch('/history') // disallow switching to /history, as it is a command handler not a subtree
66+
6467
doSwitch('/wsk/action', '/wsk/actions') // test that we switch to /wsk/actions, even when asking to change to /wsk/action
6568
bogusSwitch('actions') // type 'actions' while in /wsk/actions, and expect error
6669
doSwitch('/wsk/trigger', '/wsk/triggers') // test that we switch to /wsk/triggers, even when asking to change to /wsk/trigger
@@ -86,9 +89,10 @@ describe('Change contexts via cd', function() {
8689
.catch(common.oops(this)))
8790

8891
sidecar.close(this)
89-
doSwitch('../../', '/', undefined, actionName) // actionName had better still be selected
90-
doSwitch('wsk/rules', '/wsk/rules', undefined, actionName) // actionName had better still be selected
91-
doSwitch('../..', '/', undefined, actionName) // actionName had better still be selected
92+
bogusSwitch('../../') // this would cd us to /, which is disallowed
93+
//doSwitch('../../', '/', undefined, actionName) // actionName had better still be selected
94+
// doSwitch('wsk/rules', '/wsk/rules', undefined, actionName) // actionName had better still be selected
95+
//doSwitch('../..', '/', undefined, actionName) // actionName had better still be selected
9296

9397
bogusSwitch('ffjdsjfioas990890890890')
9498

@@ -104,7 +108,7 @@ describe('Change contexts via cd', function() {
104108
doSwitch('..', '/wsk', undefined, actionName) // actionName had better still be selected
105109
doSwitch('actions', '/wsk/actions', undefined, actionName) // actionName had better still be selected
106110
doSwitch('..', '/wsk', undefined, actionName) // actionName had better still be selected
107-
doSwitch('..', '/', undefined, actionName) // actionName had better still be selected
108-
doSwitch('wsk', '/wsk', undefined, actionName) // actionName had better still be selected
111+
//doSwitch('..', '/', undefined, actionName) // actionName had better still be selected
112+
// doSwitch('wsk', '/wsk', undefined, actionName) // actionName had better still be selected
109113
bogusSwitch('ufdufdasufdsa', undefined, actionName) // actionName had better still be selected
110114
})

tests/tests/passes/03/create-then-add-parameter/with-context-switching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ describe('Create an actions, switch to parameters view, then add parameters with
7474
doAdd('action set x=6', '{"x":6}')
7575
doAdd('wsk action set x=7', '{"x":7}')
7676

77-
doSwitch('..', '/')
78-
doAdd('wsk action set x=8', '{"x":8}')
77+
//doSwitch('..', '/')
78+
//doAdd('wsk action set x=8', '{"x":8}')
7979
})

0 commit comments

Comments
 (0)