Commit 510c97ba authored by Fredrik Lundh's avatar Fredrik Lundh

return -1 for undefined groups (as implemented in 1.5.2) instead of

None (as documented) from start/end/span.  closes bug #113254
parent ff07f8c7
...@@ -46,7 +46,7 @@ def test(expression, result, exception=None): ...@@ -46,7 +46,7 @@ def test(expression, result, exception=None):
if verbose: if verbose:
print 'Running tests on character literals' print 'Running tests on character literals'
for i in range(0, 256): for i in [0, 8, 16, 32, 64, 127, 128, 255]:
test(r"""sre.match("\%03o" % i, chr(i)) != None""", 1) test(r"""sre.match("\%03o" % i, chr(i)) != None""", 1)
test(r"""sre.match("\%03o0" % i, chr(i)+"0") != None""", 1) test(r"""sre.match("\%03o0" % i, chr(i)+"0") != None""", 1)
test(r"""sre.match("\%03o8" % i, chr(i)+"8") != None""", 1) test(r"""sre.match("\%03o8" % i, chr(i)+"8") != None""", 1)
...@@ -73,6 +73,11 @@ test(r"""sre.match('x*', 'xxxa').span(0)""", (0, 3)) ...@@ -73,6 +73,11 @@ test(r"""sre.match('x*', 'xxxa').span(0)""", (0, 3))
test(r"""sre.match('x*', 'xxxa').span()""", (0, 3)) test(r"""sre.match('x*', 'xxxa').span()""", (0, 3))
test(r"""sre.match('a+', 'xxx')""", None) test(r"""sre.match('a+', 'xxx')""", None)
# bug 113254
test(r"""sre.match('(a)|(b)', 'b').start(1)""", -1)
test(r"""sre.match('(a)|(b)', 'b').end(1)""", -1)
test(r"""sre.match('(a)|(b)', 'b').span(1)""", (-1, -1))
if verbose: if verbose:
print 'Running tests on sre.sub' print 'Running tests on sre.sub'
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* 00-08-07 fl use PyOS_CheckStack() if available * 00-08-07 fl use PyOS_CheckStack() if available
* 00-08-08 fl changed findall to return empty strings instead of None * 00-08-08 fl changed findall to return empty strings instead of None
* 00-08-27 fl properly propagate memory errors * 00-08-27 fl properly propagate memory errors
* 00-09-02 fl return -1 instead of None for start/end/span
* *
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved. * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
* *
...@@ -1983,11 +1984,7 @@ match_start(MatchObject* self, PyObject* args) ...@@ -1983,11 +1984,7 @@ match_start(MatchObject* self, PyObject* args)
return NULL; return NULL;
} }
if (self->mark[index*2] < 0) { /* mark is -1 if group is undefined */
Py_INCREF(Py_None);
return Py_None;
}
return Py_BuildValue("i", self->mark[index*2]); return Py_BuildValue("i", self->mark[index*2]);
} }
...@@ -2010,11 +2007,7 @@ match_end(MatchObject* self, PyObject* args) ...@@ -2010,11 +2007,7 @@ match_end(MatchObject* self, PyObject* args)
return NULL; return NULL;
} }
if (self->mark[index*2] < 0) { /* mark is -1 if group is undefined */
Py_INCREF(Py_None);
return Py_None;
}
return Py_BuildValue("i", self->mark[index*2+1]); return Py_BuildValue("i", self->mark[index*2+1]);
} }
...@@ -2064,12 +2057,7 @@ match_span(MatchObject* self, PyObject* args) ...@@ -2064,12 +2057,7 @@ match_span(MatchObject* self, PyObject* args)
return NULL; return NULL;
} }
if (self->mark[index*2] < 0) { /* marks are -1 if group is undefined */
Py_INCREF(Py_None);
Py_INCREF(Py_None);
return Py_BuildValue("OO", Py_None, Py_None);
}
return _pair(self->mark[index*2], self->mark[index*2+1]); return _pair(self->mark[index*2], self->mark[index*2+1]);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment