Merge pull request #3092 from laloch/fix-ansi-colors

color_tools: protect short2rgb against values with leading zeroes
This commit is contained in:
Gil Forsyth 2019-04-29 15:26:03 -04:00 committed by GitHub
commit 15b09f5998
Failed to generate hash of commit
3 changed files with 35 additions and 1 deletions

24
news/fix-ansi-colors.rst Normal file
View file

@ -0,0 +1,24 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed crash while converting ANSI color codes with leading zeroes
* Fixed crash while parsing invalid ANSI color code
**Security:**
* <news item>

View file

@ -256,7 +256,14 @@ def ansi_color_escape_code_to_name(escape_code, style, reversed_style=None):
if reversed_style is None:
style, reversed_style = ansi_reverse_style(style, return_style=True)
# strip some actual escape codes, if needed.
ec = ANSI_ESCAPE_CODE_RE.match(escape_code).group(2)
match = ANSI_ESCAPE_CODE_RE.match(escape_code)
if not match:
msg = 'Invalid ANSI color sequence "{0}", using "NO_COLOR" instead.'.format(
escape_code
)
warnings.warn(msg, RuntimeWarning)
return ("NO_COLOR",)
ec = match.group(2)
names = []
n_ints = 0
seen_set_foreback = False

View file

@ -385,6 +385,9 @@ def RGB_TO_SHORT():
def short2rgb(short):
short = short.lstrip("0")
if short == "":
short = "0"
return SHORT_TO_RGB[short]