Skip to content

Commit 5a51d61

Browse files
authored
Merge pull request #843 from oskarhane/fix-nested-params
Fix nested :params bug
2 parents c676b7d + cd0af10 commit 5a51d61

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/shared/modules/commands/helpers/params.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const handleParamsCommand = (action, cmdchar, put) => {
7373
const parts = splitStringOnFirst(strippedCmd, ' ')
7474
const param = parts[1].trim()
7575
const p = new Promise((resolve, reject) => {
76-
if (/^"?\{[^}]*\}"?$/.test(param)) {
76+
if (/^"?\{.*\}"?$/.test(param)) {
7777
// JSON object string {"x": 2, "y":"string"}
7878
try {
7979
const res = jsonic(param.replace(/^"/, '').replace(/"$/, '')) // Remove any surrounding quotes

src/shared/modules/commands/helpers/params.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ describe('commandsDuck params helper', () => {
108108
expect(put).toHaveBeenCalledWith(replace({ x: 1, y: 2 }))
109109
})
110110
})
111+
test('handles :params {x: 1, y: 2, z: {a: 3}} and calls the replace action creator', () => {
112+
// Given
113+
const action = { cmd: ':params {x: 1, y: 2, z: {a: 3}}' }
114+
const cmdchar = ':'
115+
const put = jest.fn()
116+
117+
// When
118+
const p = params.handleParamsCommand(action, cmdchar, put)
119+
120+
// Then
121+
return p.then(res => {
122+
expect(res.result).toEqual({ x: 1, y: 2, z: { a: 3 } })
123+
expect(put).toHaveBeenCalledWith(replace({ x: 1, y: 2, z: { a: 3 } }))
124+
})
125+
})
111126
describe('extract key/value from params', () => {
112127
test('<key>: <value>', () => {
113128
expect(params.extractParams('foo: bar')).toEqual({

0 commit comments

Comments
 (0)