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

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

Open
dejoma opened this issue Mar 31, 2023 · 1 comment
Labels

Comments

@dejoma
Copy link

dejoma commented Mar 31, 2023

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?

@dblock
Copy link
Member

dblock commented Mar 31, 2023

  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 Rack3 breaking change with query param nil #2298.

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

@dblock dblock added the bug? label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants