-
-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dont crash due to invalid var() values #977
Conversation
The css validation functions raise `InvalidValues`. Basic CSS validation, done in Step 2, catches and emits the exception as a WARNING. In Step 3, when a var() needs to be resolved, those validation functions are called again. We must catch the `InvalidValues` in compute(), too. Currently only the `transform` property seems to be endangered.
Both, parent_style['font_size'] and INITIAL_VALUES['font_size'], are unitless integers.
Both, parent_style['word_spacing'] and INITIAL_VALUES['word_spacing'], are unitless integers.
Fallbacks for border-spacing and size contain unitless numbers
The initial values 'none' and 'normal' of string-set resp. content crash with `UnboundLocalError` in `_content_list` unless deterred.
The INITIAL_VALUES for anchor, link and lang (oops, css properties!?) is None. If the fallback value is None there is no use in calling the @registered function. Just return None.
Now all previously crashing fallback values -- see the list in #974 (comment) -- don't crash anymore. |
Was tempted to pass those insane fallback values through the proven validation functions of Step 2 and apply the @register_computer-function afterwards. But my first candidate was Nevertheless it's nagging my brain that the validation must be done twofold. Yes, I know: specified and computed are different entities, but nevertheless... |
WOW! My first unit-test! There you go 😏 Since all Be aware that if the INITIAL_VALUES are altered (by adding new properties or changing a default value) you mustn't only adapt the basic validation functions for Step 2 but also prepare the corresponding @register_computer-function for those 'raw' default values. |
When a css property is defined via the var() function and the variable contains an invalid value a WARNING is generated and either an initial or the parent-value is assigned.
In most cases the fallback is an appropriate value and computation succeeds without further intervention, but for some properties this is not the case. We could adjust
css.properties.INITIAL_VALUES
, but I suppose there are reasons for the improper values, probably they are required elsewhere.That means we must take care for those special fallback values in the corresponding @register_computer-function. Like in
border_width()
-- this function pays attention since fadb60c, 8 years ago.