Skip to content

Commit 695ac1c

Browse files
committed
Cleanup: remove leavingThisState / emitToken logic
1 parent 1f6cae9 commit 695ac1c

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

html5lib/_tokenizer.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ def emitCurrentToken(self):
284284
# Add token to the queue to be yielded
285285
if isinstance(token, Tag):
286286
token.name = token.name.translate(asciiUpper2Lower)
287+
if self.currentToken.attribute_name in self.currentToken.attributes:
288+
self.tokenQueue.append(ParseError("duplicate-attribute"))
287289
token.clearAttribute()
288290
if isinstance(token, EndTag):
289291
if token.attributes:
@@ -854,46 +856,27 @@ def beforeAttributeNameState(self):
854856

855857
def attributeNameState(self):
856858
data = self.stream.char()
857-
leavingThisState = True
858-
emitToken = False
859859
if data == "=":
860860
self.state = self.beforeAttributeValueState
861861
elif data in asciiLetters:
862862
self.currentToken.accumulateAttributeName(data + self.stream.charsUntil(asciiLetters, True))
863-
leavingThisState = False
864863
elif data == ">":
865-
# XXX If we emit here the attributes are converted to a dict
866-
# without being checked and when the code below runs we error
867-
# because data is a dict not a list
868-
emitToken = True
864+
self.emitCurrentToken()
869865
elif data in spaceCharacters:
870866
self.state = self.afterAttributeNameState
871867
elif data == "/":
872868
self.state = self.selfClosingStartTagState
873869
elif data == "\u0000":
874870
self.tokenQueue.append(ParseError("invalid-codepoint"))
875871
self.currentToken.accumulateAttributeName("\uFFFD")
876-
leavingThisState = False
877872
elif data in ("'", '"', "<"):
878873
self.tokenQueue.append(ParseError("invalid-character-in-attribute-name"))
879874
self.currentToken.accumulateAttributeName(data)
880-
leavingThisState = False
881875
elif data is EOF:
882876
self.tokenQueue.append(ParseError("eof-in-attribute-name"))
883877
self.state = self.dataState
884878
else:
885879
self.currentToken.accumulateAttributeName(data)
886-
leavingThisState = False
887-
888-
if leavingThisState:
889-
# Attributes are not dropped at this stage. That happens when the
890-
# start tag token is emitted so values can still be safely appended
891-
# to attributes, but we do want to report the parse error in time.
892-
if self.currentToken.attribute_name in self.currentToken.attributes:
893-
self.tokenQueue.append(ParseError("duplicate-attribute"))
894-
# XXX Fix for above XXX
895-
if emitToken:
896-
self.emitCurrentToken()
897880
return True
898881

899882
def afterAttributeNameState(self):

0 commit comments

Comments
 (0)