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

Wrong regexp for click.unstyle() #1216

Closed
asvetlov opened this issue Feb 1, 2019 · 1 comment
Closed

Wrong regexp for click.unstyle() #1216

asvetlov opened this issue Feb 1, 2019 · 1 comment
Milestone

Comments

@asvetlov
Copy link

asvetlov commented Feb 1, 2019

The function uses strip_ansi() which in turn depends on _ansi_re regex: https://github.com/pallets/click/blob/master/click/_compat.py#L18

The pattern is: r'\033\[((?:\d|;)*)([a-zA-Z])'.
It is a little not full: \033[?25l and \033[?25h ANSI sequences used by cursor show/hide are not covered by the pattern.

I've changed it to r'\033\[([;\?0-9]*)([a-zA-Z])', it fixes my problem.

@jcrotts jcrotts added this to the 8.0 milestone May 6, 2019
@sekenned
Copy link
Contributor

sekenned commented May 6, 2019

Yup.

>>> import re
>>>
>>> # https://github.com/pallets/click/blob/master/click/_compat.py#L18
... _ansi_re = re.compile(r'\033\[((?:\d|;)*)([a-zA-Z])')
>>>
>>> # https://github.com/pallets/click/blob/master/click/_compat.py#L569
... def strip_ansi(value):
...     return _ansi_re.sub('', value)
...
>>> test_string = "\033[?25leggs and spam\033[?25h"
>>> strip_ansi(test_string)
'\x1b[?25leggs and spam\x1b[?25h'
>>>
>>> # suggested update
... _ansi_re = re.compile(r'\033\[([;\?0-9]*)([a-zA-Z])')
>>> strip_ansi(test_string)
'eggs and spam'
>>>

Will submit PR.

@davidism davidism modified the milestones: 8.0, 7.1 Feb 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants