ITADN

Bug: pagy :keyset pagination with 'jsonapi: true' causing decoding error with certain params

#885ClosedGee-Bee 创建于 2026-03-12
bugfixed
G
Gee-Beecommented
### Disclaimer - [x] I am aware that this issue will be closed or converted to a discussion if the requested code is missing or invalid. ### Description Minimal requirements to reproduce error: - keyset pagination, - with `jsonapi: true` option, - with `page[limit]` param but without `page[page]` param. ```shell root@6a29b8ef14ee:/usr/src/backend# bin/rails c Loading development environment (Rails 7.0.8) irb(main):001:0> Pagy::VERSION => "43.3.2" irb(main):002:0> require 'pagy/console' => true irb(main):003:0> pagy(:keyset, User.order(:id), jsonapi: true, request: {params: {'page' => {'limit' => 1}}}) /usr/local/bundle/gems/pagy-43.3.2/lib/pagy/modules/b64.rb:25:in `urlsafe_decode': undefined method `end_with?' for {"limit"=>1}:Hash (NoMethodError) if !str.end_with?('=') && str.length % 4 != 0 ^^^^^^^^^^ Did you mean? index_with ``` Adding empty `page[page]` param mitigate this issue: ```shell irb(main):004:0> pagy(:keyset, User.order(:id), jsonapi: true, request: {para ms: {'page' => {'limit' => 1, 'page' => ''}}}) User Load (1.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 2]] User Load (1.0ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC => [#<Pagy::Keyset::ActiveRecord:0x00007f337f6dfc40 ... `` This problem does not concern offset pagination: ```shell irb(main):004:0> pagy(:offset, ["a", "b"], jsonapi: true, request: {params: {'page' => {'limi t' => 1}}}) => [#<Pagy::Offset:0x00007f337fefd1c0 ..., ["a"]] ```
关闭于 2026-03-13 1 条评论