Skip to content

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

Merged
jlw merged 1 commit intomasterfrom
allow-blank-non-string-non-required
Apr 9, 2025
Merged

Do not try to coerce "" for numeric & date params#1
jlw merged 1 commit intomasterfrom
allow-blank-non-string-non-required

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