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
|
||||
|
||||
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
|
||||
safeTags :: [Tag String] -> [Tag String]
|
||||
safeTags [] = []
|
||||
|
||||
8
test.hs
8
test.hs
@ -1,7 +1,7 @@
|
||||
import Text.HTML.SanitizeXSS
|
||||
|
||||
main = do
|
||||
let test = " <a href='unsafe://hack.com'>anchor</a> <img src='evil://evil.com' /> </foo> "
|
||||
let result = (sanitizeXSS test)
|
||||
let expected = " <a>anchor</a> <img /> "
|
||||
putStrLn $ if result == expected then "pass" else "failure parsing:" ++ (show test) ++ "\nexpected:" ++ (show expected) ++ "\nactual: " ++ (show result)
|
||||
let test = " <a href='unsafe://hack.com'>anchor</a> <img src='evil://evil.com' /> </foo> <br></br> "
|
||||
let actual = (sanitizeXSS test)
|
||||
let expected = " <a>anchor</a> <img /> <br /> "
|
||||
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