Skip to content

Commit 5770d05

Browse files
author
James Graham
committed
Add in select scope
--HG-- extra : rebase_source : 5f1d51f4a4a368c83054d9d06aeacc7316267a15
1 parent 8597a27 commit 5770d05

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

html5lib/html5parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,8 @@ def startTagSelect(self, token):
22212221

22222222
def startTagInput(self, token):
22232223
self.parser.parseError("unexpected-input-in-select")
2224-
if self.tree.elementInScope("select", variant="table"):
2224+
if self.tree.elementInScope("select", variant="select"):
2225+
assert self.parser.innerHTML
22252226
self.endTagSelect(impliedTagToken("select"))
22262227
return token
22272228

@@ -2253,7 +2254,7 @@ def endTagOptgroup(self, token):
22532254
{"name": "optgroup"})
22542255

22552256
def endTagSelect(self, token):
2256-
if self.tree.elementInScope("select", variant="table"):
2257+
if self.tree.elementInScope("select", variant="select"):
22572258
node = self.tree.openElements.pop()
22582259
while node.name != "select":
22592260
node = self.tree.openElements.pop()

html5lib/treebuilders/_base.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,21 @@ def elementInScope(self, target, variant=None):
159159

160160
listElementsMap = {
161161
None:scopingElements,
162-
"button":scopingElements | set([(namespaces["html"], "button")]),
163-
"list":scopingElements | set([(namespaces["html"], "ol"),
164-
(namespaces["html"], "ul")]),
165-
"table":set([(namespaces["html"], "html"),
166-
(namespaces["html"], "table")])
162+
"button":(scopingElements | set([(namespaces["html"], "button")]), False),
163+
"list":(scopingElements | set([(namespaces["html"], "ol"),
164+
(namespaces["html"], "ul")]), False),
165+
"table":(set([(namespaces["html"], "html"),
166+
(namespaces["html"], "table")]), False),
167+
"select":(set(["optgroup", "option"]), True)
167168
}
168-
listElements = listElementsMap[variant]
169+
listElements, invert = listElementsMap[variant]
169170

170171
for node in reversed(self.openElements):
171172
if (node.name == target and not exactNode or
172173
node == target and exactNode):
173174
return True
174-
elif node.nameTuple in listElements:
175+
elif ((not invert and node.nameTuple in listElements) or
176+
(invert and node.nameTuple not in listElements)):
175177
return False
176178

177179
assert False # We should never reach this point

0 commit comments

Comments
 (0)