fix: properly percent-decode URL-encoded form values in import
Build and Deploy / build-and-deploy (push) Successful in 1m35s
Build and Deploy / build-and-deploy (push) Successful in 1m35s
The urldecode helper in parseFormBody was using Html.urlDecode which only handled %%20, %%23, and %%25. Full URLs encode colons, slashes, and dots as %%3A, %%2F, and %%2E, so they were never decoded. The scraper received the still-encoded URL and failed to fetch it. Replace Html.urlDecode with a proper percent-decode that handles all %%XX hex sequences using digitToInt.
This commit is contained in:
+8
-2
@@ -17,7 +17,7 @@ import Control.Monad (forM_, forever, when)
|
|||||||
import Data.ByteString.Builder (lazyByteString)
|
import Data.ByteString.Builder (lazyByteString)
|
||||||
import Data.ByteString.Lazy (ByteString)
|
import Data.ByteString.Lazy (ByteString)
|
||||||
import qualified Data.ByteString.Lazy as LB
|
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.IORef (IORef, atomicModifyIORef', newIORef, readIORef, writeIORef)
|
||||||
import Data.List (isSuffixOf)
|
import Data.List (isSuffixOf)
|
||||||
import Data.Map.Strict (Map)
|
import Data.Map.Strict (Map)
|
||||||
@@ -226,7 +226,13 @@ parseFormBody body =
|
|||||||
parsePair part = case T.splitOn "=" part of
|
parsePair part = case T.splitOn "=" part of
|
||||||
[key, val] -> Just (urldecode key, urldecode val)
|
[key, val] -> Just (urldecode key, urldecode val)
|
||||||
_ -> Nothing
|
_ -> 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.
|
-- | Locate the scrape-recipe script: check PATH first, then relative to project.
|
||||||
findScrapeScript :: IO FilePath
|
findScrapeScript :: IO FilePath
|
||||||
|
|||||||
Reference in New Issue
Block a user