From 57545fdb02e7c82228a592d7965b1a0b23b1a91a Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Wed, 11 May 2022 16:19:42 +0200 Subject: [PATCH] Do not filter out parameters with the same name in pagination links --- src/Yesod/Paginator/Widgets.hs | 10 ++++++---- test/Yesod/Paginator/WidgetsSpec.hs | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Yesod/Paginator/Widgets.hs b/src/Yesod/Paginator/Widgets.hs index 7c97088..4003a3f 100644 --- a/src/Yesod/Paginator/Widgets.hs +++ b/src/Yesod/Paginator/Widgets.hs @@ -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 [] = "" diff --git a/test/Yesod/Paginator/WidgetsSpec.hs b/test/Yesod/Paginator/WidgetsSpec.hs index e8afb6f..9b27ba6 100644 --- a/test/Yesod/Paginator/WidgetsSpec.hs +++ b/test/Yesod/Paginator/WidgetsSpec.hs @@ -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 @@ -52,6 +53,27 @@ spec = withApp $ do , "" ] + 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 + [ "" + ] + describe "ellipsed" $ it "works" $ do get $ EllipsedR 10 3 3