mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Merge pull request #3092 from laloch/fix-ansi-colors
color_tools: protect short2rgb against values with leading zeroes
This commit is contained in:
commit
15b09f5998
3 changed files with 35 additions and 1 deletions
24
news/fix-ansi-colors.rst
Normal file
24
news/fix-ansi-colors.rst
Normal 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>
|
|
@ -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
|
||||
|
|
|
@ -385,6 +385,9 @@ def RGB_TO_SHORT():
|
|||
|
||||
|
||||
def short2rgb(short):
|
||||
short = short.lstrip("0")
|
||||
if short == "":
|
||||
short = "0"
|
||||
return SHORT_TO_RGB[short]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue