grape icon indicating copy to clipboard operation
grape copied to clipboard

given arg_one require arg_two of array -> auto passes empty string to array when empty array is given

Open dejoma opened this issue 2 years ago • 1 comments

desc 'Breaking Grape', security: [jwt: []], success: { code: 201, model: SomeRepresenter }
      params do
        with documentation: { param_type: 'body' } do
          requires :arg_one, type: String, values: %w[one two three]
          given arg_one: ->(type) { type == 'two' } do
            requires :arg_two, type: Array[String], allow_blank: false
          end
        end
      end
end

POST to that endpoint with { "arg_one": "two", "arg_two": [] } and somehow the array will contain an empty string. Fails both with allow_blank false and allow_blank.

How does the empty string end up there? How does it not fail when allow_blank false?

dejoma avatar Mar 31 '23 09:03 dejoma

  1. Does it work if type is not an array (e.g. String)?
  2. Does it work without given?
  3. Confirm the version of Grape and Rack, could be related to https://github.com/ruby-grape/grape/issues/2298.

Probably a bug in some combination. Would appreciate a unit test that reproduces the problem in a pull request.

dblock avatar Mar 31 '23 13:03 dblock