mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
URL decode text input in fastcgi server, including %uXXXX sequences.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import PGF (PGF)
|
import PGF (PGF)
|
||||||
import qualified PGF
|
import qualified PGF
|
||||||
import FastCGIUtils
|
import FastCGIUtils
|
||||||
|
import URLEncoding
|
||||||
|
|
||||||
import Network.CGI
|
import Network.CGI
|
||||||
import Text.JSON
|
import Text.JSON
|
||||||
@@ -42,7 +43,7 @@ cgiMain pgf =
|
|||||||
outputJSON json
|
outputJSON json
|
||||||
where
|
where
|
||||||
getText :: CGI String
|
getText :: CGI String
|
||||||
getText = liftM (fromMaybe "") $ getInput "input"
|
getText = liftM (maybe "" urlDecodeUnicode) $ getInput "input"
|
||||||
|
|
||||||
getTree :: CGI PGF.Tree
|
getTree :: CGI PGF.Tree
|
||||||
getTree = do mt <- getInput "tree"
|
getTree = do mt <- getInput "tree"
|
||||||
|
|||||||
18
src/server/URLEncoding.hs
Normal file
18
src/server/URLEncoding.hs
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user