Permalink
Browse files
Also raise RuntimeError in libc.regex_first_group_match().
- Loading branch information...
Showing
with
10 additions
and
4 deletions.
-
+5
−3
native/libc.c
-
+5
−1
native/libc_test.py
|
|
@@ -302,8 +302,9 @@ func_regex_first_group_match(PyObject *self, PyObject *args) { |
|
|
// patterns like ${foo/x*/y}.
|
|
|
|
|
|
if (regcomp(&pat, pattern, REG_EXTENDED) != 0) {
|
|
|
fprintf(stderr, "Invalid regex at runtime\n");
|
|
|
return PyLong_FromLong(-1);
|
|
|
PyErr_SetString(PyExc_RuntimeError,
|
|
|
"Invalid regex syntax (func_regex_first_group_match)");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
debug("first_group_match pat %s str %s pos %d", pattern, str, pos);
|
|
|
@@ -338,7 +339,8 @@ static PyMethodDef methods[] = { |
|
|
"Raises RuntimeError if the regex is invalid."},
|
|
|
{"regex_first_group_match", func_regex_first_group_match, METH_VARARGS,
|
|
|
"If the regex matches the string, return the start and end position of the "
|
|
|
"first group. None for no match; -1 for invalid regex."},
|
|
|
"first group. Returns None if there is no match. Raises RuntimeError if "
|
|
|
"the regex is invalid."},
|
|
|
{NULL, NULL},
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -74,7 +74,7 @@ def testRegex(self): |
|
|
actual = libc.regex_match(pat, s)
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
# Error.
|
|
|
# Syntax Error
|
|
|
self.assertRaises(
|
|
|
RuntimeError, libc.regex_match, r'*', 'abcd')
|
|
|
|
|
|
@@ -94,6 +94,10 @@ def testRegexFirstGroupMatch(self): |
|
|
(8, 10),
|
|
|
libc.regex_first_group_match('(X.)', s, 6))
|
|
|
|
|
|
# Syntax Error
|
|
|
self.assertRaises(
|
|
|
RuntimeError, libc.regex_first_group_match, r'*', 'abcd', 0)
|
|
|
|
|
|
def testRealpathFailOnNonexistentDirectory(self):
|
|
|
# This behaviour is actually inconsistent with GNU readlink,
|
|
|
# but matches behaviour of busybox readlink
|
|
|
|
0 comments on commit
cbc99f0