escape data-warning attr

This commit is contained in:
Rhiannon Morris 2020-09-14 02:33:27 +02:00
parent 046dc59834
commit 258b1c6102
2 changed files with 10 additions and 2 deletions

View file

@ -2,7 +2,7 @@
module BuilderQQ module BuilderQQ
(b, (b,
Builder, toLazyText, fromText, fromString, fromChar, Builder, toLazyText, fromText, fromString, fromChar,
textMap, ifJust, escId) textMap, ifJust, escId, escAttr)
where where
import Data.Char (isLower, isSpace, isDigit, isAlphaNum) import Data.Char (isLower, isSpace, isDigit, isAlphaNum)
@ -159,6 +159,14 @@ escId = foldMap esc1 . Text.unpack where
latin1Special c = latin1Special c =
c <= 'ÿ' && not (isAlphaNum c) && c /= '-' c <= 'ÿ' && not (isAlphaNum c) && c /= '-'
escAttr :: Text -> Builder
escAttr = foldMap esc1 . Text.unpack where
esc1 '<' = "&lt;"
esc1 '>' = "&gt;"
esc1 '"' = "&quot;"
esc1 '\'' = "&apos;"
esc1 c = fromChar c
class CanBuild a where class CanBuild a where
build :: a -> Builder build :: a -> Builder

View file

@ -173,7 +173,7 @@ altButton i (Image {label, path, nsfw, warning}) (Size {width, height}) = [b|@4
checked = if i == 0 then [b| checked|] else "" checked = if i == 0 then [b| checked|] else ""
idLabel = escId label idLabel = escId label
path' = pageFile path 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 :: FilePath -> [Strict.Text] -> Builder
makeTags undir tags = makeTags undir tags =