diff options
| author | bjorn <bjorn@bringert.net> | 2008-08-24 17:39:24 +0000 |
|---|---|---|
| committer | bjorn <bjorn@bringert.net> | 2008-08-24 17:39:24 +0000 |
| commit | 5c0487200f2642ffe597431ae4f685a0f35d35f1 (patch) | |
| tree | 62f3351394e2dca4087544801dc96c89e834ace2 /src/server/URLEncoding.hs | |
| parent | 23a6375ced4110e650cb3b4ab10614f6a5314995 (diff) | |
URL decode text input in fastcgi server, including %uXXXX sequences.
Diffstat (limited to 'src/server/URLEncoding.hs')
| -rw-r--r-- | src/server/URLEncoding.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/server/URLEncoding.hs b/src/server/URLEncoding.hs new file mode 100644 index 000000000..ad5fb0dd9 --- /dev/null +++ b/src/server/URLEncoding.hs @@ -0,0 +1,18 @@ +module URLEncoding where + +import Data.Bits (shiftL, (.|.)) +import Data.Char (chr,digitToInt,isHexDigit) + + +urlDecodeUnicode :: String -> String +urlDecodeUnicode [] = "" +urlDecodeUnicode ('%':'u':x1:x2:x3:x4:s) + | all isHexDigit [x1,x2,x3,x4] = + chr ( digitToInt x1 `shiftL` 12 + .|. digitToInt x2 `shiftL` 8 + .|. digitToInt x3 `shiftL` 4 + .|. digitToInt x4) : urlDecodeUnicode s +urlDecodeUnicode ('%':x1:x2:s) | isHexDigit x1 && isHexDigit x2 = + chr ( digitToInt x1 `shiftL` 4 + .|. digitToInt x2) : urlDecodeUnicode s +urlDecodeUnicode (c:s) = c : urlDecodeUnicode s |
