From 0109b1cd26226e95b80806369e0b2f43ad5045f6 Mon Sep 17 00:00:00 2001 From: Pratik Bhusal Date: Mon, 1 May 2023 21:51:10 -0500 Subject: [PATCH] Fix(IndexError): Handle unexpected System level pygments import Problem: If pygments is installed via pip, it will be used regardless of the locally shipped pygments dependency. Solution: Defensively checks bounds to ensure no index exception occurs. --- src/syntax_highlighting/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/syntax_highlighting/main.py b/src/syntax_highlighting/main.py index c4369ac..b2a86a6 100644 --- a/src/syntax_highlighting/main.py +++ b/src/syntax_highlighting/main.py @@ -53,7 +53,11 @@ # to show the user AND # The "language aliases": short, cryptic names for internal # use by HtmlFormatter -LANGUAGES_MAP = {lex[0]: lex[1][0] for lex in get_all_lexers()} +LANGUAGES_MAP = { + lex[0]: lex[1][0] + for lex in get_all_lexers() + if len(lex) > 1 and len(lex[1]) +} ERR_LEXER = ("Error: Selected language not found.
"