aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regexp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-07-31 11:31:33 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2013-07-31 11:31:33 -0400
commit1346f40b584d8072bdacdf312027c0ef57e4b7c2 (patch)
treee97890df7e1ed57b315c755983da442f7e794077 /src/backend/utils/adt/regexp.c
parented33ad39a2f353acc3d38591a749f324de3b6c23 (diff)
downloadpostgresql-1346f40b584d8072bdacdf312027c0ef57e4b7c2.tar.gz
postgresql-1346f40b584d8072bdacdf312027c0ef57e4b7c2.zip
Fix regexp_matches() handling of zero-length matches.
We'd find the same match twice if it was of zero length and not immediately adjacent to the previous match. replace_text_regexp() got similar cases right, so adjust this search logic to match that. Note that even though the regexp_split_to_xxx() functions share this code, they did not display equivalent misbehavior, because the second match would be considered degenerate and ignored. Jeevan Chalke, with some cosmetic changes by me.
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r--src/backend/utils/adt/regexp.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index 67e205d0816..b15b0905b74 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -957,14 +957,13 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags,
break;
/*
- * Advance search position. Normally we start just after the end of
- * the previous match, but always advance at least one character (the
- * special case can occur if the pattern matches zero characters just
- * after the prior match or at the end of the string).
+ * Advance search position. Normally we start the next search at the
+ * end of the previous match; but if the match was of zero length, we
+ * have to advance by one character, or we'd just find the same match
+ * again.
*/
- if (start_search < pmatch[0].rm_eo)
- start_search = pmatch[0].rm_eo;
- else
+ start_search = prev_match_end;
+ if (pmatch[0].rm_so == pmatch[0].rm_eo)
start_search++;
if (start_search > wide_len)
break;