From 258b1c61021db0b0e5f838526ac182760d5df113 Mon Sep 17 00:00:00 2001 From: Rhiannon Morris Date: Mon, 14 Sep 2020 02:33:27 +0200 Subject: [PATCH] escape data-warning attr --- make-pages/BuilderQQ.hs | 10 +++++++++- make-pages/SinglePage.hs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/make-pages/BuilderQQ.hs b/make-pages/BuilderQQ.hs index 6f8eb78..097094c 100644 --- a/make-pages/BuilderQQ.hs +++ b/make-pages/BuilderQQ.hs @@ -2,7 +2,7 @@ module BuilderQQ (b, Builder, toLazyText, fromText, fromString, fromChar, - textMap, ifJust, escId) + textMap, ifJust, escId, escAttr) where import Data.Char (isLower, isSpace, isDigit, isAlphaNum) @@ -159,6 +159,14 @@ escId = foldMap esc1 . Text.unpack where latin1Special c = c <= 'ΓΏ' && not (isAlphaNum c) && c /= '-' +escAttr :: Text -> Builder +escAttr = foldMap esc1 . Text.unpack where + esc1 '<' = "<" + esc1 '>' = ">" + esc1 '"' = """ + esc1 '\'' = "'" + esc1 c = fromChar c + class CanBuild a where build :: a -> Builder diff --git a/make-pages/SinglePage.hs b/make-pages/SinglePage.hs index c116dab..5b73264 100644 --- a/make-pages/SinglePage.hs +++ b/make-pages/SinglePage.hs @@ -173,7 +173,7 @@ altButton i (Image {label, path, nsfw, warning}) (Size {width, height}) = [b|@4 checked = if i == 0 then [b| checked|] else "" idLabel = escId label path' = pageFile path - warning' = ifJust warning \w -> [b| data-warning="$w"|] + warning' = ifJust warning \(escAttr -> w) -> [b| data-warning="$w"|] makeTags :: FilePath -> [Strict.Text] -> Builder makeTags undir tags =