Skip to content

Do not try to coerce "" for numeric & date params #1

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

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

jlw
Copy link
Owner

@jlw jlw commented Apr 9, 2025

Description

When using an HTML form for searching or filtering and a field is left blank, Rails puts an empty string in the params hash, and this raised an unexpected InvalidParameterError when we defined the param as a non-required Integer, Float, Date, etc.

Now we will treat that empty string as an un-supplied param and only reject it if the param is flagged as required.

Additional Notes

  • added shared examples for Float tests
  • nested shared examples in the appropriate scope

I suggested this improvement for the rails_param gem over a year ago (nicolasblanco#103) - the maintainers mistakenly thought this was a breaking change for JSON APIs and declined to provide an example.

When using an HTML form for searching or filtering and a field is left
blank, Rails puts an empty string in the params hash, and this raised
an unexpected InvalidParameterError when we defined the param as a
non-required Integer, Float, Date, etc.

Now we will treat that empty string as an un-supplied param and only
reject it if the param is flagged as required.

- added shared examples for Float tests
- nested shared examples in the appropriate scope
@jlw jlw merged commit 378d82d into master Apr 9, 2025
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

Successfully merging this pull request may close these issues.

1 participant