Skip to content

Commit

Permalink
Git issue 546: Partial match not working in some instances with non-g…
Browse files Browse the repository at this point in the history
…reedy capture
  • Loading branch information
Matthew Barnett committed Nov 6, 2024
1 parent 64834c7 commit 930983a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version: 2024.11.6

Git issue 546: Partial match not working in some instances with non-greedy capture

Version: 2024.9.14

Reverted to actions/download-artifact@v3 and actions/upload-artifact@v3 in main.yml because GitHub Actions failed when using them.
Expand Down
18 changes: 0 additions & 18 deletions regex_3/_regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -16535,9 +16535,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
RE_PARTIAL_RIGHT)
return RE_ERROR_PARTIAL;

if (pos >= limit)
break;

/* Look for the tail string. */
found = string_search(state, test, pos + 1, limit +
length, TRUE, &is_partial);
Expand Down Expand Up @@ -16593,9 +16590,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
RE_PARTIAL_RIGHT)
return RE_ERROR_PARTIAL;

if (pos >= limit)
break;

/* Look for the tail string. */
found = string_search_fld(state, test, pos + 1, limit,
&new_pos, &is_partial);
Expand Down Expand Up @@ -16651,9 +16645,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
if (pos <= state->text_start && state->partial_side == RE_PARTIAL_LEFT)
return RE_ERROR_PARTIAL;

if (pos <= limit)
break;

/* Look for the tail string. */
found = string_search_fld_rev(state, test, pos - 1,
limit, &new_pos, &is_partial);
Expand Down Expand Up @@ -16713,9 +16704,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
RE_PARTIAL_RIGHT)
return RE_ERROR_PARTIAL;

if (pos >= limit)
break;

/* Look for the tail string. */
found = string_search_ign(state, test, pos + 1, limit +
length, TRUE, &is_partial);
Expand Down Expand Up @@ -16773,9 +16761,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
if (pos <= state->text_start && state->partial_side == RE_PARTIAL_LEFT)
return RE_ERROR_PARTIAL;

if (pos <= limit)
break;

/* Look for the tail string. */
found = string_search_ign_rev(state, test, pos - 1,
limit - length, TRUE, &is_partial);
Expand Down Expand Up @@ -16833,9 +16818,6 @@ Py_LOCAL_INLINE(int) basic_match(RE_State* state, BOOL search) {
if (pos <= state->text_start && state->partial_side == RE_PARTIAL_LEFT)
return RE_ERROR_PARTIAL;

if (pos <= limit)
break;

/* Look for the tail string. */
found = string_search_rev(state, test, pos - 1, limit -
length, TRUE, &is_partial);
Expand Down
2 changes: 1 addition & 1 deletion regex_3/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"VERSION1", "X", "VERBOSE", "W", "WORD", "error", "Regex", "__version__",
"__doc__", "RegexFlag"]

__version__ = "2.5.147"
__version__ = "2.5.148"

# --------------------------------------------------------------------
# Public interface.
Expand Down
10 changes: 10 additions & 0 deletions regex_3/test_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4346,6 +4346,16 @@ def test_hg_bugs(self):
self.assertEqual(regex.match(r"(?i)[^/]*b/xyz", "b/xy", partial=True).span(), (0, 4))
self.assertEqual(regex.match(r"(?i)[^/]*b/xyz", "b/yz", partial=True), None)

# Git issue 546: Partial match not working in some instances with non-greedy capture
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>x', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>xyz abc', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>xyz abc foo', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>xyz abc foo ', partial=True)), True)
self.assertEqual(bool(regex.match(r'<thinking>.*?</thinking>', '<thinking>xyz abc foo bar', partial=True)), True)

def test_fuzzy_ext(self):
self.assertEqual(bool(regex.fullmatch(r'(?r)(?:a){e<=1:[a-z]}', 'e')),
True)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='regex',
version='2024.9.11',
version='2024.11.6',
description='Alternative regular expression module, to replace re.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 930983a

Please sign in to comment.