From 101690ff7bd6992039eac9f3e7ea72b93aff41f8 Mon Sep 17 00:00:00 2001 From: Yitzchak Gale Date: Tue, 26 Jun 2018 22:27:51 +0300 Subject: [PATCH] Tests for customized white list. --- test/main.hs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/main.hs b/test/main.hs index 40b9af5..eb0bf56 100644 --- a/test/main.hs +++ b/test/main.hs @@ -11,9 +11,19 @@ test f actual expected = do let result = f actual result @?= expected -sanitized :: Text -> Text -> Expectation +sanitized, sanitizedB, sanitizedC :: Text -> Text -> Expectation sanitized = test sanitize sanitizedB = test sanitizeBalance +sanitizedC = test sanitizeCustom + +sanitizeCustom :: Text -> Text +sanitizeCustom = filterTags $ mySafeTags mySafeName mySanitizeAttr + where + mySafeName t = t `elem` myTags || safeTagName t + mySanitizeAttr (key, val) | key `elem` myAttrs = Just (key, val) + mySanitizeAttr x = sanitizeAttribute x + myTags = ["custtag"] + myAttrs = ["custattr"] main :: IO () main = hspec $ do @@ -87,3 +97,15 @@ main = hspec $ do sanitizedB "" "" it "interleaved" $ sanitizedB "helloworld" "helloworld" + + describe "customized white list" $ do + it "does not filter custom tags" $ do + let custtag = "

" + sanitizedC custtag custtag + it "filters non-custom tags" $ do + sanitizedC "

" "

" + it "does not filter custom attributes" $ do + let custattr = "

" + sanitizedC custattr custattr + it "filters non-custom attributes" $ do + sanitizedC "

" "

"