Skip to content

Crashing on keys with dot #416

@KonradSwierczynski

Description

@KonradSwierczynski

Hey, I spotted strange behaviour when using keys with dots which is inconsistent and can crash validating config.

See example below:

const config = convict({
  test: {
    param: {
      doc: 'some nested parameter',
      format: String,
      default: 'foo',
    },
  },
});

// Example 1
config.load({ 'test.param': 'bar' });
config.validate({ allowed: 'strict' });  // passes validation
console.log(config.get('test.param'));  // prints out 'foo' - unexpected, since previous load should set the value or fail validation
// in this example the validate would throw an error, key with dot should not be treated as path

// Example 2
config.load({ 'someOther.param': 'baz' });
config.validate({ allowed: 'warn' });  // throws error - unexpected, should just print a warning

/* the error:
Uncaught Error: cannot find configuration param 'someOther.param'
    at walk ([...]/node_modules/convict/src/main.js:2:8321)
    at flatten ([...]/node_modules/convict/src/main.js:2:1400)
    at validate ([...]/node_modules/convict/src/main.js:2:2099)
    at Object.validate (/[...]/node_modules/convict/src/main.js:2:10481)
*/

I'm using convict in version 6.2.4 and node v18.17.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions