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

re.sub replaces only first 32 matches with re.U flag #55471

Closed
EugeneMorozov mannequin opened this issue Feb 20, 2011 · 2 comments
Closed

re.sub replaces only first 32 matches with re.U flag #55471

EugeneMorozov mannequin opened this issue Feb 20, 2011 · 2 comments
Labels

Comments

@EugeneMorozov
Copy link
Mannequin

EugeneMorozov mannequin commented Feb 20, 2011

BPO 11262

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-02-20.23:01:03.740>
created_at = <Date 2011-02-20.22:28:09.731>
labels = ['type-security', 'expert-regex', 'invalid']
title = 're.sub replaces only first 32 matches with re.U flag'
updated_at = <Date 2011-02-20.23:01:03.731>
user = 'https://bugs.python.org/EugeneMorozov'

bugs.python.org fields:

activity = <Date 2011-02-20.23:01:03.731>
actor = 'SilentGhost'
assignee = 'none'
closed = True
closed_date = <Date 2011-02-20.23:01:03.740>
closer = 'SilentGhost'
components = ['Regular Expressions']
creation = <Date 2011-02-20.22:28:09.731>
creator = 'Eugene.Morozov'
dependencies = []
files = []
hgrepos = []
issue_num = 11262
keywords = []
message_count = 2.0
messages = ['128923', '128925']
nosy_count = 2.0
nosy_names = ['SilentGhost', 'Eugene.Morozov']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'security'
url = 'https://bugs.python.org/issue11262'
versions = ['Python 2.6']

@EugeneMorozov
Copy link
Mannequin Author

EugeneMorozov mannequin commented Feb 20, 2011

There's a peculiar and difficult to find bug in the re.sub method. Try following example:
>>> text = 'X'*4096
>>> nt = re.sub(u"XX", u".", text, re.U)
>>> nt
u'............XXXXXXXXXXXXXXXXXXX' (only 32 dots, the rest of the string is not changed).

If I first compile regexp, and then perform compiled_regexp.sub, everything seems to work correctly.

@EugeneMorozov EugeneMorozov mannequin added topic-regex type-security A security issue labels Feb 20, 2011
@SilentGhost
Copy link
Mannequin

SilentGhost mannequin commented Feb 20, 2011

If you read docs carefully, you notice that re.sub doesn't accept flags argument. Its 4th argument is count, re.U numerical value is 32.

Closing as invalid. There are some duplicates too, I'm sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants