From 6de5d2e8d23c4231423a5440b16540f55bc0df96 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 31 Oct 2010 23:06:11 +0200 Subject: [PATCH] Deal with non-closing tags --- Text/HTML/SanitizeXSS.hs | 5 ++++- test.hs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Text/HTML/SanitizeXSS.hs b/Text/HTML/SanitizeXSS.hs index 0ad3e0b..530e09d 100644 --- a/Text/HTML/SanitizeXSS.hs +++ b/Text/HTML/SanitizeXSS.hs @@ -21,7 +21,10 @@ sanitizeXSS = renderTagsOptions renderOptions { safeTags m [] = concatMap go $ Map.toList m where - go (name, i) = replicate i $ TagClose name + go (name, i) + | noClosing name = [] + | otherwise = replicate i $ TagClose name + noClosing = flip elem ["br", "img"] safeTags m (t@(TagClose name):tags) | safeTagName name = case Map.lookup name m of diff --git a/test.hs b/test.hs index 840f59b..80d603e 100644 --- a/test.hs +++ b/test.hs @@ -1,8 +1,8 @@ import Text.HTML.SanitizeXSS main = do - let test = " safeanchor

Unbalanced" + let test = " safeanchor

Unbalanced" let actual = (sanitizeXSS test) - let expected = " safeanchor
Unbalanced" + let expected = " safeanchor
Unbalanced" putStrLn $ "testing: " ++ test putStrLn $ if actual == expected then "pass" else "failure\n" ++ "\nexpected:" ++ (show expected) ++ "\nactual: " ++ (show actual)