Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cssutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,13 @@ def _parse(
"""
wellformed = True

if new is None:
# ``new`` is optional, but the default productions record the
# wellformed state into it (new['wellformed'] = False). Give them a
# throwaway dict when a caller that does not track it (e.g. parsing
# a bare property name) passes None, to avoid a TypeError.
new = {}

if initialtoken:
# add initialtoken to tokenizer
def tokens():
Expand Down
13 changes: 13 additions & 0 deletions tests/test_cssstyledeclaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def test_init(self):
assert 'top: 0' == s.cssText
assert sheet == s.parentRule

def test_at_in_property_name(self):
"CSSStyleDeclaration with an '@' in a property name"
# A property name containing '@' reached the default productions with
# new=None and used to raise TypeError ('NoneType' object does not
# support item assignment). It should be reported as a normal CSS
# error instead: parsing a whole sheet drops the bad property and keeps
# the rest, and building a declaration directly raises SyntaxErr.
sheet = cssutils.parseString('a { col@or: red; width: 1px }')
assert '1px' == sheet.cssRules[0].style.getPropertyValue('width')

with pytest.raises(xml.dom.SyntaxErr):
cssutils.css.CSSStyleDeclaration(cssText='col@or: red')

def test_items(self):
"CSSStyleDeclaration[CSSName]"
s = cssutils.css.CSSStyleDeclaration()
Expand Down