Skip to content

TNTLexer crashes with input '0' #1568

@kurtmckee

Description

@kurtmckee

While working on #1425 I used Hypothesis to help me identify JSON lexing issues.

Hypothesis immediately reported a crash bug in the TNT lexer. It crashes with an IndexError if you pass 0 as the input string:

>>> import pygments.lexers
>>> list(pygments.lexers.TNTLexer().get_tokens('0'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Kurt\Documents\dev\pygments\pygments\lexer.py", line 188, in streamer
    for _, t, v in self.get_tokens_unprocessed(text):
  File "C:\Users\Kurt\Documents\dev\pygments\pygments\lexers\tnt.py", line 215, in get_tokens_unprocessed
    start = end = self.formula(start, text)
  File "C:\Users\Kurt\Documents\dev\pygments\pygments\lexers\tnt.py", line 107, in formula
    if text[start] in '[]':  # fantasy push or pop
IndexError: string index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions