From dc2d5d9cd0d34dd9318726c7534d683813410fc5 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 8 Apr 2021 09:34:38 -0400 Subject: [PATCH 1/3] Stop moving session language ahead of reqLangs Yesod.Core.Handler.languages checks first for a language set in the user's session, prepending that value to YesodRequest{reqLangs}, so it is respected above all else if present. For context, reqLangs itself also includes the session, but just later in line: langs' = catMaybes [ lookup langKey gets -- Query _LANG , lookup langKey cookies -- Cookie _LANG , lookupText langKey session -- Session _LANG ] ++ langs -- Accept-Language(s) In #1720, it was raised that allowing the session (something implicitly present for any request) to override a query parameter (something explicitly given on that request) is surprising. We decided (without knowing what order reqLangs was doing) that query, cookie, session, accept was best and languages should be changed to do that. Conveniently, this just makes languages equivalent to reqLangs, so that is what this patch does. --- yesod-core/src/Yesod/Core/Handler.hs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/yesod-core/src/Yesod/Core/Handler.hs b/yesod-core/src/Yesod/Core/Handler.hs index 063ad1f9..67b9b53d 100644 --- a/yesod-core/src/Yesod/Core/Handler.hs +++ b/yesod-core/src/Yesod/Core/Handler.hs @@ -1226,10 +1226,10 @@ cacheBySet key value = do -- Languages are determined based on the following (in descending order -- of preference): -- --- * The _LANG user session variable. --- -- * The _LANG get parameter. -- +-- * The _LANG user session variable. +-- -- * The _LANG cookie. -- -- * Accept-Language HTTP header. @@ -1239,10 +1239,7 @@ cacheBySet key value = do -- -- This is handled by parseWaiRequest (not exposed). languages :: MonadHandler m => m [Text] -languages = do - mlang <- lookupSession langKey - langs <- reqLangs <$> getRequest - return $ maybe id (:) mlang langs +languages = reqLangs <$> getRequest lookup' :: Eq a => a -> [(a, b)] -> [b] lookup' a = map snd . filter (\x -> a == fst x) From 7875930c430aeb70de76dd6490709bdded6928b1 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 8 Apr 2021 09:53:58 -0400 Subject: [PATCH 2/3] Version bump --- yesod-core/ChangeLog.md | 4 ++++ yesod-core/src/Yesod/Core/Handler.hs | 4 ++++ yesod-core/yesod-core.cabal | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/yesod-core/ChangeLog.md b/yesod-core/ChangeLog.md index 80eac463..eaf1f87a 100644 --- a/yesod-core/ChangeLog.md +++ b/yesod-core/ChangeLog.md @@ -1,5 +1,9 @@ # ChangeLog for yesod-core +## 1.6.18.9 + +* Change order of priority in `languages`[#1721](https://github.com/yesodweb/yesod/pull/1721) + ## 1.6.18.8 * Fix test suite for wai-extra change around vary header diff --git a/yesod-core/src/Yesod/Core/Handler.hs b/yesod-core/src/Yesod/Core/Handler.hs index 67b9b53d..119b4d64 100644 --- a/yesod-core/src/Yesod/Core/Handler.hs +++ b/yesod-core/src/Yesod/Core/Handler.hs @@ -1238,6 +1238,10 @@ cacheBySet key value = do -- If a matching language is not found the default language will be used. -- -- This is handled by parseWaiRequest (not exposed). +-- +-- __NOTE__: Before version @1.6.18.9@, this function prioritized the session +-- variable above all other sources. +-- languages :: MonadHandler m => m [Text] languages = reqLangs <$> getRequest diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index 685b95e5..6e799418 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -1,5 +1,5 @@ name: yesod-core -version: 1.6.18.8 +version: 1.6.18.9 license: MIT license-file: LICENSE author: Michael Snoyman From 0c2a4ebc817a05790dc42ef5338d20bbbd7dbbf4 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Thu, 8 Apr 2021 10:07:18 -0400 Subject: [PATCH 3/3] Bump minor, not patch --- yesod-core/ChangeLog.md | 2 +- yesod-core/src/Yesod/Core/Handler.hs | 2 +- yesod-core/yesod-core.cabal | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/yesod-core/ChangeLog.md b/yesod-core/ChangeLog.md index eaf1f87a..70041a9f 100644 --- a/yesod-core/ChangeLog.md +++ b/yesod-core/ChangeLog.md @@ -1,6 +1,6 @@ # ChangeLog for yesod-core -## 1.6.18.9 +## 1.6.19.0 * Change order of priority in `languages`[#1721](https://github.com/yesodweb/yesod/pull/1721) diff --git a/yesod-core/src/Yesod/Core/Handler.hs b/yesod-core/src/Yesod/Core/Handler.hs index 119b4d64..d6ad08da 100644 --- a/yesod-core/src/Yesod/Core/Handler.hs +++ b/yesod-core/src/Yesod/Core/Handler.hs @@ -1239,7 +1239,7 @@ cacheBySet key value = do -- -- This is handled by parseWaiRequest (not exposed). -- --- __NOTE__: Before version @1.6.18.9@, this function prioritized the session +-- __NOTE__: Before version @1.6.19.0@, this function prioritized the session -- variable above all other sources. -- languages :: MonadHandler m => m [Text] diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index 6e799418..41a228b4 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -1,5 +1,5 @@ name: yesod-core -version: 1.6.18.9 +version: 1.6.19.0 license: MIT license-file: LICENSE author: Michael Snoyman