minimize br and img
This commit is contained in:
parent
ca3b8e7b0c
commit
b051155461
@ -12,7 +12,9 @@ import Codec.Binary.UTF8.String ( encodeString, decodeString )
|
|||||||
import Text.HTML.TagSoup
|
import Text.HTML.TagSoup
|
||||||
|
|
||||||
sanitizeXSS :: String -> String
|
sanitizeXSS :: String -> String
|
||||||
sanitizeXSS = renderTags . safeTags . parseTagsOptions parseOptions { optTagPosition = True }
|
sanitizeXSS = renderTagsOptions renderOptions {
|
||||||
|
optMinimize = \x -> x `elem` ["br","img"]
|
||||||
|
} . safeTags . parseTagsOptions parseOptions { optTagPosition = True }
|
||||||
where
|
where
|
||||||
safeTags :: [Tag String] -> [Tag String]
|
safeTags :: [Tag String] -> [Tag String]
|
||||||
safeTags [] = []
|
safeTags [] = []
|
||||||
|
|||||||
8
test.hs
8
test.hs
@ -1,7 +1,7 @@
|
|||||||
import Text.HTML.SanitizeXSS
|
import Text.HTML.SanitizeXSS
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
let test = " <a href='unsafe://hack.com'>anchor</a> <img src='evil://evil.com' /> </foo> "
|
let test = " <a href='unsafe://hack.com'>anchor</a> <img src='evil://evil.com' /> </foo> <br></br> "
|
||||||
let result = (sanitizeXSS test)
|
let actual = (sanitizeXSS test)
|
||||||
let expected = " <a>anchor</a> <img /> "
|
let expected = " <a>anchor</a> <img /> <br /> "
|
||||||
putStrLn $ if result == expected then "pass" else "failure parsing:" ++ (show test) ++ "\nexpected:" ++ (show expected) ++ "\nactual: " ++ (show result)
|
putStrLn $ if actual == expected then "pass" else "failure parsing:" ++ (show test) ++ "\nexpected:" ++ (show expected) ++ "\nactual: " ++ (show actual)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user