Skip to content
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

CSS, "tuple index out of range" #1653

Closed
jaggzh opened this issue May 31, 2022 · 1 comment
Closed

CSS, "tuple index out of range" #1653

jaggzh opened this issue May 31, 2022 · 1 comment
Labels
crash Problems preventing documents from being rendered
Milestone

Comments

@jaggzh
Copy link

jaggzh commented May 31, 2022

  File ".../__init__.py", line 239, in __init__
    preprocess_stylesheet(
  File ".../css/__init__.py", line 1017, in preprocess_stylesheet
    rule_descriptors = dict(
  File ".../css/validation/descriptors.py", line 49, in preprocess_descriptors
    value = function(tokens, base_url)
  File ".../css/utils.py", line 153, in wrapper
    result = function(remove_whitespace(part), *args)
  File ".../css/validation/descriptors.py", line 145, in src
    tokens, token = tokens[:-1], tokens[-1]
IndexError: tuple index out of range

It's crashing on invalid .css entries with commas at the end, like:

@font-face {
  font-family: 'en-sym';
  src: url('res/DejaVuSans.ttf');
  src: url('res/DejaVuSans.ttf') format('truetype'),
}

It'd be difficult for most users to find what the problem is. I modified the code to print tokens to try to debug it:

Tokens: (<FunctionBlock url( … )>, <FunctionBlock format( … )>)
Tokens: (<FunctionBlock url( … )>, <FunctionBlock format( … )>)
Tokens: (<FunctionBlock url( … )>,)
Tokens: (<FunctionBlock url( … )>, <FunctionBlock format( … )>, <LiteralToken ,>)

So I found the issue was the comma, but maybe some useful output would be good here? The error is because tokens is empty, and the code's test for <= 2 items then assumes there's an actual last item anyway.

@liZe liZe added the crash Problems preventing documents from being rendered label May 31, 2022
@liZe liZe closed this as completed in e4885f9 Jun 1, 2022
@liZe liZe added this to the 56.0 milestone Jun 1, 2022
@liZe
Copy link
Member

liZe commented Jun 1, 2022

Thanks a lot for the bug report. It’s fixed and tested on master, feedback is welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants