File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
tests/AdvancedHTMLParserTests Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -593,12 +593,12 @@ def value(self):
593593 '''
594594 return self .getAttribute ('value' , '' )
595595
596- def getAttribute (self , attrName ):
596+ def getAttribute (self , attrName , defaultValue = None ):
597597 '''
598598 getAttribute - Gets an attribute on this tag. Be wary using this for classname, maybe use addClass/removeClass. Attribute names are all lowercase.
599599 @return - The attribute value, or None if none exists.
600600 '''
601- return self .attributes .get (attrName , None )
601+ return self .attributes .get (attrName , defaultValue )
602602
603603 def setAttribute (self , attrName , attrValue ):
604604 '''
Original file line number Diff line number Diff line change 1+ * 6.6.4 (unreleased)
2+ - Fix regression where "AdvancedTag.getAttribute" method would not accept a default
3+ (second param).
4+ - Fix calling ".value" on an AdvancedTag to get the "value" attribute (was
5+ broken by previous regression)
6+
7+
18* 6.6.3 Oct 03 2016
29- Fix no-value attributes not appearing in html output (like "checked" on an input). Was in attributes, but not in html output.
310
Original file line number Diff line number Diff line change @@ -113,6 +113,21 @@ def test_noValueAttributes(self):
113113 assert 'checked' in tag .attributes
114114 assert 'checked' in tag .outerHTML
115115
116+ def test_valueMethod (self ):
117+ parser = AdvancedHTMLParser ()
118+ parser .parseStr ('<input id="item" type="text" value="hello" />' )
119+
120+ tag = parser .getElementById ('item' )
121+ assert tag .value == 'hello'
122+
123+ def test_attributeDefault (self ):
124+ parser = AdvancedHTMLParser ()
125+ parser .parseStr ('<input id="item" type="text" value="hello" />' )
126+
127+ tag = parser .getElementById ('item' )
128+ assert tag .getAttribute ('type' , 'bloogity' ) == 'text'
129+ assert tag .getAttribute ('woogity' , 'snoogity' ) == 'snoogity'
130+
116131
117132if __name__ == '__main__' :
118133 pipe = subprocess .Popen ('GoodTests.py "%s"' % (sys .argv [0 ],), shell = True ).wait ()
You can’t perform that action at this time.
0 commit comments