Euphoria Ticket #624: regex is_match() logical inconsistancy/bug

The function is_match() in the regex library is supposed to tell you if your pattern (the needle) matches the entire subject (the haystack).

However, it takes an optional "from" parameter -- the subscript to start matching on the subject. In other words, the haystack doesn't always really start at position 1. If there is a successful pattern match, the function checks to see if the returned match starts with 1 and ends at length(haystack), in which case it returns true, else false.

But if the "from" parameter is set to anything other than 1, then is_match() will always return false because even if there is a match, the start will never be 1 because it can't be less than "from", which is greater than 1.

Therefore, this line:

if sequence(m) and length(m) > 0 and m[1][1] = 1 and m[1][2] = length(haystack) then 

should instead be:

if sequence(m) and length(m) > 0 and m[1][1] = from and m[1][2] = length(haystack) then 

with documentation updated to note that the "entire haystack" is to be [from..$] rather than always [1..$].

Either that, or drop the "from" parameter as it makes no sense. Possibly that is what was intended in the first place.

Details

Type: Bug Report Severity: Normal Category: Library Routine
Assigned To: unknown Status: Fixed Reported Release: 4.0.0
Fixed in SVN #: View VCS: none Milestone: 4.0.1

1. Comment by SDPringle Mar 09, 2011

He is right.

2. Comment by SDPringle Mar 09, 2011

See: hg:euphoria/rev/1768651497c1

changeset: 4735:1768651497c1 branch: 4.0 user: Shawn Pringle <shawn.pringle@gmail.com> date: Wed Mar 09 16:17:58 2011 -0300 files: docs/release/4.0.1.txt description:

  • added log entry to release notes for ticket 624 - fixes 624

3. Comment by mattlewis Mar 09, 2011

Note that due to major regressions, commits for this ticket have been removed from the tip of the repository.

4. Comment by mattlewis Mar 11, 2011

See: hg:euphoria/rev/05416383a492

changeset: 4745:05416383a492 branch: 4.0 user: Matt Lewis date: Fri Mar 11 12:44:06 2011 -0500 files: docs/release/4.0.1.txt include/std/regex.e description:

  • regex:is_match() uses from parameter
  • fixes ticket 624
  • originally fixed in 18648e34631642fbf2909d3a8335e577df4cb089

Search



Quick Links

User menu

Not signed in.

Misc Menu