[>=1.7.0] Crash for latex inline mode

Open Beginner friendly
#252 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cli

Research direction

Reproduce the crash with the attached id_000007.txt and the shown ansi2html --latex --inline command. Start in converter.py at _handle_ansi_code, where the traceback shows the KeyError for ansi38, then trace the inline LaTeX path. Done means this input completes without crashing.

Written by the indexing model from the issue text.

Description

fix

The input file as following:
id_000007.txt

run with command:

$ cat id_000007.txt | ansi2html --latex --inline

crash with the error:

$ cat output/crashes/id:000007* | ansi2html --latex --inline
Traceback (most recent call last):
  File "/home/xxx/Workspace/.venv/bin/ansi2html", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 815, in main
    output = conv.convert(
             ^^^^^^^^^^^^^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 627, in convert
    attrs = self.prepare(ansi, ensure_trailing_newline=ensure_trailing_newline)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 604, in prepare
    body, styles = self.apply_regex(ansi)
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 353, in apply_regex
    no_cursor_parts = self._collapse_cursor(all_parts)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 574, in _collapse_cursor
    for part in parts:
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 430, in _apply_regex
    yield from self._handle_ansi_code(part, styles_used, state)
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 547, in _handle_ansi_code
    style = [
            ^
  File "/home/xxx/Workspace/.venv/lib/python3.11/site-packages/ansi2html/converter.py", line 550, in <listcomp>
    if self.styles[klass].kwl[0][0] == "color"
       ~~~~~~~~~~~^^^^^^^
KeyError: 'ansi38'
### Tasks
Dominant language
Python
Stars
425
Forks
85
Avg merge
7h 49m
Merged PRs (30d)
12

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pycontribs/ansi2html

All issues in pycontribs/ansi2html

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.