Skip to content

Commit e131583

Browse files
committed
Add tests that the validating parser raises errors on invalid attribute names.
1 parent c3f38da commit e131583

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

tests/AdvancedHTMLParserTests/test_ValidateInvalidHtml.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import subprocess
88

99
from AdvancedHTMLParser.Validator import ValidatingAdvancedHTMLParser
10-
from AdvancedHTMLParser.exceptions import InvalidCloseException, MissedCloseException
10+
from AdvancedHTMLParser.exceptions import InvalidCloseException, MissedCloseException, InvalidAttributeNameException
1111

1212

1313
MULTIPLE_ROOT = """
@@ -49,7 +49,59 @@
4949
</html>
5050
"""
5151

52+
53+
VALUE_OUTSIDE_QUOTES = """
54+
<html>
55+
<div id="one" class="hello world"; name="blah">
56+
<span> hey </span>
57+
</div>
58+
</html>
59+
"""
60+
61+
62+
INVALID_ATTR_NAME = """
63+
<html>
64+
<div id="one" 9gag="two" >
65+
<span> Yo </span>
66+
</div>
67+
</html>
68+
"""
69+
5270
class TestValidateInvalidHtml(object):
71+
'''
72+
TestValidateInvalidHtml - Test class for ValidatingAdvancedHTMLParser
73+
'''
74+
75+
76+
def test_handleValueOutsideQuotes(self):
77+
'''
78+
test_handleValueOutsideQuotes - Assert we validate properly when an invalid character outside quotes
79+
'''
80+
parser = ValidatingAdvancedHTMLParser()
81+
82+
gotException = False
83+
try:
84+
parser.parseStr(VALUE_OUTSIDE_QUOTES)
85+
except InvalidAttributeNameException:
86+
gotException = True
87+
88+
assert gotException is True , 'Failed to raise validation error on symbol, ";" , outside quotes of value.'
89+
90+
91+
def test_handleInvalidAttributeName(self):
92+
'''
93+
test_handleInvalidAttributeName - Tests that we raise validation error on invalid attribute name
94+
'''
95+
parser = ValidatingAdvancedHTMLParser()
96+
97+
gotException = False
98+
try:
99+
parser.parseStr(INVALID_ATTR_NAME)
100+
except InvalidAttributeNameException:
101+
gotException = True
102+
103+
assert gotException is True , 'Failed to raise validation error on invalid attribute name, "9gag". Cannot start with integer.'
104+
53105

54106
def test_HandleMultipleRoot(self):
55107
'''

0 commit comments

Comments
 (0)