From e8c6873fadef9acde6aa204599a1adad5cb0947d Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 15 Jul 2019 13:43:16 +1200 Subject: [PATCH] Data.CSS.Style.Selector.Index: fix potential crash. --- src/Data/CSS/Style/Selector/Index.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Data/CSS/Style/Selector/Index.hs b/src/Data/CSS/Style/Selector/Index.hs index c77a3fe..ff9e7db 100644 --- a/src/Data/CSS/Style/Selector/Index.hs +++ b/src/Data/CSS/Style/Selector/Index.hs @@ -41,17 +41,18 @@ simpleSelector (Descendant _ s) = s simpleSelector (Adjacent _ s) = s simpleSelector (Sibling _ s) = s -addRuleForSelector self rule [] = self {unindexed = rule : unindexed self} -addRuleForSelector self rule selector = self { +addRuleForSelector self@(StyleIndex index _) rule selector + | Just key <- selectorKey selector = self { indexed = insert key (rule : lookup' key index) index - } where - key = selectorKey selector - index = indexed self + } + | otherwise = self {unindexed = rule : unindexed self} -selectorKey (tok@(Tag _) : _) = tok -selectorKey (tok@(Id _) : _) = tok -selectorKey (tok@(Class _) : _) = tok -selectorKey (Property prop _ : _) = Property prop Exists +selectorKey (tok@(Tag _) : _) = Just tok +selectorKey (tok@(Id _) : _) = Just tok +selectorKey (tok@(Class _) : _) = Just tok +selectorKey (Property prop _ : _) = Just $ Property prop Exists +--selectorKey (_ : tokens) = selectorKey tokens +selectorKey [] = Nothing ---- -- 2.30.2