diff --git a/src/Roux/Server.hs b/src/Roux/Server.hs index 52db74b..8ba1412 100644 --- a/src/Roux/Server.hs +++ b/src/Roux/Server.hs @@ -17,7 +17,7 @@ import Control.Monad (forM_, forever, when) import Data.ByteString.Builder (lazyByteString) import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as LB -import Data.Char (toLower) +import Data.Char (digitToInt, toLower) import Data.IORef (IORef, atomicModifyIORef', newIORef, readIORef, writeIORef) import Data.List (isSuffixOf) import Data.Map.Strict (Map) @@ -226,7 +226,13 @@ parseFormBody body = parsePair part = case T.splitOn "=" part of [key, val] -> Just (urldecode key, urldecode val) _ -> Nothing - urldecode = T.pack . Html.urlDecode . T.replace "+" " " + -- Proper percent-decode for all %XX sequences (not just %20/%23/%25). + urldecode = T.pack . go . T.unpack . T.replace "+" " " + go [] = [] + go ('%' : a : b : rest) = + let hexVal = digitToInt a * 16 + digitToInt b + in toEnum hexVal : go rest + go (c : rest) = c : go rest -- | Locate the scrape-recipe script: check PATH first, then relative to project. findScrapeScript :: IO FilePath