Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Schema don't filter undescribed params #366

Closed
semenovDL opened this issue Oct 1, 2017 · 7 comments
Closed

Default Schema don't filter undescribed params #366

semenovDL opened this issue Oct 1, 2017 · 7 comments

Comments

@semenovDL
Copy link

require 'dry-validation'

schema = Dry::Validation.Schema do
  required(:email).filled(:str?)
end

validated =  schema.call(email: 'admin@google.com', password: 'hackyou')
puts validated.success? # => true
puts validated.output # => {:email=>"admin@google.com", :password=>"hackyou"}
@pashagray
Copy link

I think that such behavior is OK. Because we do not specify that any other params should be filtered. Maybe it is good idea to implement such DSL:

schema = Dry::Validation.Schema do
  method :default # as it used to be
  method :strict # makes :success? to be false if any not declared keys are present
  method :filter # just filters keys not declared keys
end

@pashagray
Copy link

pashagray commented May 5, 2018

This was considered as bug and solved
#66

Howto:

Dry::Validation.Schema do
  configure do
    config.input_processor = :sanitizer
  end

  key(:email).required

  key(:age).maybe(:int?, gt?: 18)

  key(:address).schema do
    key(:city).required
    key(:street).required
  end
end

result = schema.(
  email: 'jane@doe',
  age: 19,
  such: 'key',
  address: { city: 'NYC', street: 'Street', wow: 'bad' }
)

result.output
# {  email: 'jane@doe', age: 19, address: { city: 'NYC', street: 'Street' }

@kurko
Copy link

kurko commented Jan 19, 2019

Yep. I arrived here after looking at #66. Add config.input_processor = :sanitizer.

@flash-gordon
Copy link
Member

This will be the default behavior in the next release

@mengqing
Copy link

mengqing commented May 4, 2019

I thought sanitizer is already the default setting but apparently its not. Is there a way to set this as the default setting without having to create a base schema that every other schemas have to nest with?

@solnic
Copy link
Member

solnic commented May 4, 2019

@mengqing no, you either configure it in each schema, or use a base schema and inherit from it

@mengqing
Copy link

mengqing commented May 4, 2019

@solnic Thanks for the quick reply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants