Skip to content

Crashing on keys with dot #416

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions