@@ -284,6 +284,8 @@ def emitCurrentToken(self):
284
284
# Add token to the queue to be yielded
285
285
if isinstance (token , Tag ):
286
286
token .name = token .name .translate (asciiUpper2Lower )
287
+ if self .currentToken .attribute_name in self .currentToken .attributes :
288
+ self .tokenQueue .append (ParseError ("duplicate-attribute" ))
287
289
token .clearAttribute ()
288
290
if isinstance (token , EndTag ):
289
291
if token .attributes :
@@ -854,46 +856,27 @@ def beforeAttributeNameState(self):
854
856
855
857
def attributeNameState (self ):
856
858
data = self .stream .char ()
857
- leavingThisState = True
858
- emitToken = False
859
859
if data == "=" :
860
860
self .state = self .beforeAttributeValueState
861
861
elif data in asciiLetters :
862
862
self .currentToken .accumulateAttributeName (data + self .stream .charsUntil (asciiLetters , True ))
863
- leavingThisState = False
864
863
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 ()
869
865
elif data in spaceCharacters :
870
866
self .state = self .afterAttributeNameState
871
867
elif data == "/" :
872
868
self .state = self .selfClosingStartTagState
873
869
elif data == "\u0000 " :
874
870
self .tokenQueue .append (ParseError ("invalid-codepoint" ))
875
871
self .currentToken .accumulateAttributeName ("\uFFFD " )
876
- leavingThisState = False
877
872
elif data in ("'" , '"' , "<" ):
878
873
self .tokenQueue .append (ParseError ("invalid-character-in-attribute-name" ))
879
874
self .currentToken .accumulateAttributeName (data )
880
- leavingThisState = False
881
875
elif data is EOF :
882
876
self .tokenQueue .append (ParseError ("eof-in-attribute-name" ))
883
877
self .state = self .dataState
884
878
else :
885
879
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 ()
897
880
return True
898
881
899
882
def afterAttributeNameState (self ):
0 commit comments