Skip to content

Commit e2c1753

Browse files
committed
make deepchildren include the root node for asterisk to work toplevel
1 parent 9f2e538 commit e2c1753

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

yesod-test/Yesod/Test/CssQuery.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ data Selector
5454
| ByAttrContains Text Text
5555
| ByAttrStarts Text Text
5656
| ByAttrEnds Text Text
57-
| Asterisk -- TODO: This needs to be deep.
57+
| Asterisk
5858
deriving (Show, Eq)
5959

6060

@@ -78,14 +78,14 @@ parseQuery = parseOnly cssQuery
7878

7979
-- Below this line is the Parsec parser for css queries.
8080
cssQuery :: Parser [[SelectorGroup]]
81-
cssQuery = many (char ' ') >> sepBy rules (char ',' >> many (char ' '))
81+
cssQuery = (many (char ' ') >> sepBy rules (char ',' >> many (char ' ')))
8282

8383
rules :: Parser [SelectorGroup]
8484
rules = many $ directChildren <|> deepChildren
8585

8686
directChildren :: Parser SelectorGroup
8787
directChildren =
88-
string "> " >> (many (char ' ')) >> DirectChildren <$> pOptionalTrailingSpace parseSelectorTypes
88+
string "> " >> many (char ' ') >> DirectChildren <$> pOptionalTrailingSpace parseSelectorTypes
8989

9090
deepChildren :: Parser SelectorGroup
9191
deepChildren = pOptionalTrailingSpace $ DeepChildren <$> parseSelectorTypes

yesod-test/Yesod/Test/TransversingCSS.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ runQuery html query = concatMap (runGroup html) query
8989
runGroup :: Cursor -> [SelectorGroup] -> [Cursor]
9090
runGroup c [] = [c]
9191
runGroup c (DirectChildren s:gs) = concatMap (flip runGroup gs) $ c $/ selectors s
92-
runGroup c (DeepChildren s:gs) = concatMap (flip runGroup gs) $ c $// selectors s
92+
runGroup c (DeepChildren s:gs) = concatMap (flip runGroup gs) $ c $.// selectors s
9393

9494
selectors :: [SelectorType] -> Cursor -> [Cursor]
9595
selectors cs c
@@ -125,7 +125,9 @@ selector c (ByAttrEnds n v) =
125125
case attribute (Name n Nothing Nothing) c of
126126
t:_ -> v `T.isSuffixOf` t
127127
[] -> False
128-
selector _ Asterisk = True
128+
selector c Asterisk = case node c of
129+
NodeElement _ -> True
130+
_ -> False
129131

130132
pseudoselector :: Cursor -> Selector -> PseudoSelector -> Bool
131133
pseudoselector c _ FirstChild = null $ precedingSibling c

yesod-test/test/main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ main = hspec $ do
130130
findBySelector_ html "p:nth-child(-n-1)" @?= []
131131
findBySelector_ html "p:nth-child(-n-0)" @?= []
132132
findBySelector_ html "p:nth-child(-n+3)" @?= ["<p>1</p>", "<p>2</p>", "<p>3</p>"]
133+
let ps = ["<p>" <> show n <> "</p>" | n <- [1..10]] in
134+
findBySelector_ html "*" @?= ["<html>" <> concat ps <> "</html>"] <> ps
133135

134136
describe "HTML parsing" $ do
135137
it "XHTML" $

yesod-test/yesod-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: yesod-test
2-
version: 1.6.23.1
2+
version: 1.6.24
33
license: MIT
44
license-file: LICENSE
55
author: Nubis <[email protected]>

0 commit comments

Comments
 (0)