[New-bugs-announce] [issue22362] Warn about octal escapes > 0o377 in re

Serhiy Storchaka report at bugs.python.org
Mon Sep 8 13:07:20 CEST 2014


New submission from Serhiy Storchaka:

Currently the re module accepts octal escapes from \400 to \777, but ignore highest bit.

>>> re.search(r'\542', 'abc')
<_sre.SRE_Match object; span=(1, 2), match='b'>

This behavior looks surprising and is inconsistent with the regex module which preserve highest bit. Such escaping is not portable across different regular exception engines.

I propose to add a warning when octal escape value is larger than 0o377. Here is preliminary patch which adds UserWarning. Or may be better to emit DeprecationWarning and then replace it by ValueError in future releases?

----------
components: Library (Lib), Regular Expressions
files: re_octal_escape_overflow.patch
keywords: patch
messages: 226570
nosy: ezio.melotti, mrabarnett, pitrou, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Warn about octal escapes > 0o377 in re
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file36571/re_octal_escape_overflow.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22362>
_______________________________________


More information about the New-bugs-announce mailing list