Skip to content

Avoid TypeError parsing a property name containing '@' - #81

Open
eeshsaxena wants to merge 1 commit into
jaraco:mainfrom
eeshsaxena:fix/typeerror-at-in-property-name
Open

Avoid TypeError parsing a property name containing '@'#81
eeshsaxena wants to merge 1 commit into
jaraco:mainfrom
eeshsaxena:fix/typeerror-at-in-property-name

Conversation

@eeshsaxena

Copy link
Copy Markdown

A property name containing @ makes cssutils raise a bare TypeError instead of a CSS error:

import cssutils
cssutils.css.CSSStyleDeclaration(cssText='col@or: red')
# TypeError: 'NoneType' object does not support item assignment  (util.py, ATKEYWORD)

The default productions added by _adddefaultproductions record the wellformed state with new['wellformed'] = False, but _parse's new argument is optional and defaults to None. Parsing a bare property name passes new=None, so when the name contains @ the ATKEYWORD production dereferences None. I default new to a throwaway dict at the top of _parse when it is None, so the malformed name is reported as a normal CSS error (dropped when parsing a whole sheet, SyntaxErr when building a declaration directly). Valid CSS is unaffected.

Added a test to TestCSSStyleDeclaration; it raises TypeError on main and passes with the change, and the declaration suite still passes. Found it by fuzzing parseString.

The default productions record the wellformed state via new['wellformed'], but
_parse's 'new' argument is optional and defaults to None. Parsing a bare
property name (which passes new=None) that contains an '@' reached the
ATKEYWORD production and raised 'NoneType' object does not support item
assignment. Give _parse a throwaway dict when new is None so the input is
reported as a normal CSS error instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant