- Issue #3629: Fix sre "bytecode" validator for an end case.

Reviewed by Amaury.
This commit is contained in:
Guido van Rossum 2008-09-10 14:27:00 +00:00
parent 24329ba176
commit e3c4fd9cc0
3 changed files with 10 additions and 3 deletions

View File

@ -116,6 +116,10 @@ class ReTests(unittest.TestCase):
self.assertRaises(ValueError, re.findall, pattern, 'A', re.I) self.assertRaises(ValueError, re.findall, pattern, 'A', re.I)
self.assertRaises(ValueError, re.compile, pattern, re.I) self.assertRaises(ValueError, re.compile, pattern, re.I)
def test_bug_3629(self):
# A regex that triggered a bug in the sre-code validator
re.compile("(?P<quote>)(?(quote))")
def test_sub_template_numeric_escape(self): def test_sub_template_numeric_escape(self):
# bug 776311 and friends # bug 776311 and friends
self.assertEqual(re.sub('x', r'\0', 'x'), '\0') self.assertEqual(re.sub('x', r'\0', 'x'), '\0')

View File

@ -68,6 +68,8 @@ C-API
Library Library
------- -------
- Issue #3629: Fix sre "bytecode" validator for an end case.
- Issue #3811: The Unicode database was updated to 5.1. - Issue #3811: The Unicode database was updated to 5.1.
- Issue #3809: Fixed spurious 'test.blah' file left behind by test_logging. - Issue #3809: Fixed spurious 'test.blah' file left behind by test_logging.

View File

@ -2781,17 +2781,18 @@ _compile(PyObject* self_, PyObject* args)
arg = *code++; \ arg = *code++; \
VTRACE(("%lu (arg)\n", (unsigned long)arg)); \ VTRACE(("%lu (arg)\n", (unsigned long)arg)); \
} while (0) } while (0)
#define GET_SKIP \ #define GET_SKIP_ADJ(adj) \
do { \ do { \
VTRACE(("%p= ", code)); \ VTRACE(("%p= ", code)); \
if (code >= end) FAIL; \ if (code >= end) FAIL; \
skip = *code; \ skip = *code; \
VTRACE(("%lu (skip to %p)\n", \ VTRACE(("%lu (skip to %p)\n", \
(unsigned long)skip, code+skip)); \ (unsigned long)skip, code+skip)); \
if (code+skip < code || code+skip > end) \ if (code+skip-adj < code || code+skip-adj > end)\
FAIL; \ FAIL; \
code++; \ code++; \
} while (0) } while (0)
#define GET_SKIP GET_SKIP_ADJ(0)
static int static int
_validate_charset(SRE_CODE *code, SRE_CODE *end) _validate_charset(SRE_CODE *code, SRE_CODE *end)
@ -3098,7 +3099,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; GET_ARG;
if (arg >= groups) if (arg >= groups)
FAIL; FAIL;
GET_SKIP; GET_SKIP_ADJ(1);
code--; /* The skip is relative to the first arg! */ code--; /* The skip is relative to the first arg! */
/* There are two possibilities here: if there is both a 'then' /* There are two possibilities here: if there is both a 'then'
part and an 'else' part, the generated code looks like: part and an 'else' part, the generated code looks like: