Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unicode safety of percentDecode #25

Open
claudeha opened this issue Mar 9, 2016 · 2 comments
Open

unicode safety of percentDecode #25

claudeha opened this issue Mar 9, 2016 · 2 comments

Comments

@claudeha
Copy link

claudeha commented Mar 9, 2016

http://hackage.haskell.org/package/happstack-server-7.4.6.1/docs/Happstack-Server-SURI.html#v:percentDecode

appears not to be unicode-safe - single codepoints can be encoded as multiple percents like %XX%YY%ZZ , probably using UTF-8, for example → is encoded as something that percentDecode mangles into → when viewed in my browser

probably the way to fix it would be to assume ASCII except for % and construct a ByteString to decode with Text decodeUtf8With (something that doesn't crash, using replacement characters) or similar

@ddssff
Copy link
Contributor

ddssff commented Mar 10, 2016

I don't quite understand. Could you give a worked example of how this fails?

@claudeha
Copy link
Author

percentDecode.hs for testing without having to install happstack-server:

import Data.Char

percentDecode :: String -> String
percentDecode [] = ""
percentDecode ('%':x1:x2:s) | isHexDigit x1 && isHexDigit x2 =
    chr (digitToInt x1 * 16 + digitToInt x2) : percentDecode s
percentDecode (c:s) = c : percentDecode s

main = do
  putStrLn "→"
  putStrLn (percentDecode "%E2%86%92") -- percent encoded "→" copy-pasted from browser address bar

output:

$ runghc percentDecode.hs
→
â
$ runghc percentDecode.hs | hd
00000000  e2 86 92 0a c3 a2 c2 86  c2 92 0a                 |...........|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants