Skip to content

Commit

Permalink
Do not filter out parameters with the same name in pagination links
Browse files Browse the repository at this point in the history
  • Loading branch information
eahlberg committed May 11, 2022
1 parent 7e8c2ba commit 57545fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Yesod/Paginator/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ getUpdateGetParams
getUpdateGetParams pageParamName = do
params <- handlerToWidget $ reqGetParams <$> getRequest
pure
$ \number ->
nubOn fst
$ [(unPageParamName pageParamName, tshow number)]
<> params
$ \number -> formatParams number params
where
formatParams :: Show a => a -> [(Text, Text)] -> [(Text, Text)]
formatParams number params =
let name = unPageParamName pageParamName
in [(name, tshow number)] <> filter ((/=) name . fst) params

renderGetParams :: [(Text, Text)] -> Text
renderGetParams [] = ""
Expand Down
24 changes: 23 additions & 1 deletion test/Yesod/Paginator/WidgetsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import SpecHelper

spec :: Spec
spec = withApp $ do
describe "simple" $ it "works" $ do
describe "simple" $ do
it "works" $ do
get $ SimpleR 10 3 3

statusIs 200
Expand Down Expand Up @@ -52,6 +53,27 @@ spec = withApp $ do
, "</ul>"
]

it "includes all parameters with the same name" $ do
get $ SimpleR 10 3 3

request $ do
addGetParam "p" "3"
addGetParam "ids[]" "1"
addGetParam "ids[]" "2"
setUrl $ SimpleR 10 3 3

statusIs 200

bodyContains $ concat
[ "<ul class=\"pagination\">"
, "<li class=\"prev\"><a href=\"?p=2&amp;ids%5B%5D=2&amp;ids%5B%5D=1\">«</a></li>"
, "<li class=\"prev\"><a href=\"?p=2&amp;ids%5B%5D=2&amp;ids%5B%5D=1\">2</a></li>"
, "<li class=\"active disabled\"><a>3</a></li>"
, "<li class=\"next\"><a href=\"?p=4&amp;ids%5B%5D=2&amp;ids%5B%5D=1\">4</a></li>"
, "<li class=\"next\"><a href=\"?p=4&amp;ids%5B%5D=2&amp;ids%5B%5D=1\">»</a></li>"
, "</ul>"
]

describe "ellipsed" $ it "works" $ do
get $ EllipsedR 10 3 3

Expand Down

0 comments on commit 57545fd

Please sign in to comment.