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
Labels
Milestone

Comments

@asvetlov
Copy link

@asvetlov 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
@jcrotts jcrotts added the enhancement label May 6, 2019
@sekenned

This comment has been minimized.

Copy link
Contributor

@sekenned 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.