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

TNTLexer: Don't crash on unexpected EOL. #1570

Merged
merged 3 commits into from
Oct 14, 2020
Merged

Conversation

Kenny2github
Copy link
Contributor

@Kenny2github Kenny2github commented Oct 12, 2020

Closes #1568 which is blocking #1425

Catch IndexErrors in each line and error the rest of the line,
leaving whatever tokens were found.
@Kenny2github
Copy link
Contributor Author

Force pushed to just the one commit (the others are already in the repo)

Copy link
Collaborator

@Anteru Anteru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case for this (it should crash without the change applied.)

@Kenny2github
Copy link
Contributor Author

(Seen 4 hours ago, been writing tests for the whole lexer ever since)

pygments/lexers/tnt.py:
* Fix indentation on import
* Fix: TNTLexer.cur is class-level reference if not initialized
  in get_tokens_unprocessed, so init it in __init__ too
* Fix: Fantasy markers are not allowed as components of other formulas,
  so have a dedicated check for them in the body of get_tokens_unprocessed
  which disables the normal formula handling if present
* Clarify TNTLexer.lineno docstring
* Attempt to discard tokens before an IndexError

+tests/test_tnt.py:
* Test every method, and test both +ve and -ve matches for most
* Lexer fixture is test-level to reinitialize cur clean each time
* Don't test actual get_tokens_unprocessed method (besides for fantasy markers)
  because the text testing is left to examplefiles

AUTHORS:
+ Add myself to credits :)
@Anteru
Copy link
Collaborator

Anteru commented Oct 13, 2020

That looks fairly comprehensive, thanks! I'll wait for the tests to finish, then merge -- thanks for your contribution.

@Kenny2github
Copy link
Contributor Author

Glad to be of service! Sorry for the original issue I caused. At least I got good tests in :)

@Kenny2github
Copy link
Contributor Author

/cc @Anteru just noting that tests have passed! I don't want to hold up the people in #1425 any longer than I have to. Thanks :)

@Anteru Anteru merged commit 3e1b79c into pygments:master Oct 14, 2020
@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Oct 14, 2020
@Anteru Anteru self-assigned this Oct 14, 2020
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Oct 24, 2020
@Anteru Anteru added this to the 2.7.2 milestone Oct 24, 2020
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.

TNTLexer crashes with input '0'
2 participants