Fix NoMethodError with tampered params#872
Merged
ddnexus merged 1 commit intoddnexus:masterfrom Feb 5, 2026
Merged
Conversation
The page param could be an Array or Hash which will raise a NoMethodError for `to_i`. By casting to a String, this will fix the issue and return 0 when an invalid value is found.
Owner
|
Simple and effective! Thank you Chris. |
Contributor
|
Neat, thanks. For some reason our bot visitors' favorite thing to do is include a second |
Contributor
Author
|
That is annoying. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've had some requests come in that are clearly messing with params such as
?page[]=2and?page[testing]=1This causes an error when casting
to_ihere since page is an Array or Hash and not a String.pagy/gem/lib/pagy/classes/request.rb
Line 24 in 53f6bbb
It raises a
NoMethodErrorwhich isn't ideal to rescue from in a controller.By casting to a String, this will fix the issue and return 0 when an invalid value is found since:
This should make Pagy raise a lot less errors when the page param is tampered with by bots or malicious users.