dry-rb / dry-schema

Coercion and validation for data structures
https://dry-rb.org/gems/dry-schema
MIT License
415 stars 108 forks source link

Keys validation ignores substrings of defined keys #385

Closed pharmaceutics closed 2 years ago

pharmaceutics commented 2 years ago

Describe the bug

In schemas with validate_keys enabled, any input key that is a substring of either a defined key (including nested) or a full key path in dot notation will pass the validation.

To Reproduce

schema = Dry::Schema.define do
  config.validate_keys = true

  optional(:name).filled(:string)
  optional(:address).hash do
    optional(:city).filled(:string)
  end
end

schema.call(am: 'Jane', city: 'NYC', dress: { cit: '?' })
=> #<Dry::Schema::Result{} errors={} path=[]>

Expected behavior

schema.call(am: 'Jane', city: 'NYC', dress: { cit: '?' })
=> #<Dry::Schema::Result{} errors={:am=>["is not allowed"], :city=>["is not allowed"], :dress=>{:cit=>["is not allowed"]}} path=[]>

My environment