Commit 9d26c3f3 authored by Tiger's avatar Tiger

Handle nil values in Grape length limit validator

Changelog: fixed
parent 68467582
......@@ -7,7 +7,7 @@ module API
def validate_param!(attr_name, params)
value = params[attr_name]
return if value.size <= @option
return if value.nil? || value.size <= @option
raise Grape::Exceptions::Validation.new(
params: [@scope.full_name(attr_name)],
......
......@@ -22,4 +22,10 @@ RSpec.describe API::Validations::Validators::Limit do
expect_validation_error('test' => "#{'a' * 256}")
end
end
context 'value is nil' do
it 'does not raise a validation error' do
expect_no_validation_error('test' => nil)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment