@@ -12,9 +12,9 @@ import Data.Char (toLower)
1212import qualified Data.CharSet as Set
1313import qualified Data.CharSet.Unicode.Category as Set
1414import Data.List
15+import Data.List.Split
1516import Data.Monoid
1617import Data.Proxy
17−import Data.String.Utils
1818import GHC.TypeLits
1919import Servant.API
2020
@@ -68,14 +68,17 @@ data HeaderArg = HeaderArg
6868instance Show HeaderArg where
6969 show (HeaderArg n) = toValidFunctionName ("header" <> n)
7070 show (ReplaceHeaderArg n p)
71− | pn `startswith` p = pv <> " + \"" <> rp <> "\""
72− | pn `endswith` p = "\"" <> rp <> "\" + " <> pv
73− | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p) <> "\""
71+ | pn `isPrefixOf` p = pv <> " + \"" <> rp <> "\""
72+ | pn `isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
73+ | pn `isInfixOf` p = "\"" <> (replace pn ("\" + " <> pv <> " + \"") p)
74+ <> "\""
7475 | otherwise = p
7576 where
7677 pv = toValidFunctionName ("header" <> n)
7778 pn = "{" <> n <> "}"
7879 rp = replace pn "" p
80+ -- Nicked from Data.String.Utils, works on lists
81+ replace old new l = intercalate new . splitOn old $ l
7982
8083-- | Attempts to reduce the function name provided to that allowed by JS.
8184-- https://mathiasbynens.be/notes/javascript-identifiers