Skip to content

Commit be654ac

Browse files
authored
fix: put ttl option should throw an error if the value is a quoted number (string) (#72)
1 parent 3c93412 commit be654ac

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/StateStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class StateStore {
122122
const details = { key, value, options }
123123
validateKey(key, details)
124124
validateValue(value, details)
125-
validateInput(options, joi.object().label('options').keys({ ttl: joi.number() }), details)
125+
validateInput(options, joi.object().label('options').keys({ ttl: joi.number() }).options({ convert: false }), details)
126126

127127
const ttl = options.ttl || StateStore.DefaultTTL // => undefined, null, 0 sets to default
128128
logger.debug(`put '${key}' with ttl ${ttl}`)

test/StateStore.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('put', () => {
6666
await global.expectToThrowBadArg(state.put.bind(state, 'key', 'value', 'options'), ['object', 'options'], { ...expectedDetails, options: 'options' })
6767
await global.expectToThrowBadArg(state.put.bind(state, 'key', 'value', { nonexiting__option: 'value' }), ['nonexiting__option', 'not allowed'], { ...expectedDetails, options: { nonexiting__option: 'value' } })
6868
await global.expectToThrowBadArg(state.put.bind(state, 'key', 'value', { ttl: 'value' }), ['ttl', 'number'], { ...expectedDetails, options: { ttl: 'value' } })
69+
await global.expectToThrowBadArg(state.put.bind(state, 'key', 'value', { ttl: '1' }), ['ttl', 'number'], { ...expectedDetails, options: { ttl: '1' } })
6970
})
7071
test('calls _put with default ttl when options is undefined or options.ttl is = 0', async () => {
7172
const state = new StateStore(true)

0 commit comments

Comments
 (0)