Bug 5019 – In std.regex, empty capture at end of string causes error

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-10-08T11:52:00Z
Last change time
2011-06-06T08:18:29Z
Assigned to
andrei
Creator
petevik38

Comments

Comment #0 by petevik38 — 2010-10-08T11:52:59Z
An empty capture before the end of the string seems to work fine: auto m = match( "abc", "ab(.*)c" ); writefln( "'%s'", m.captures[1] ); -> '' An empty capture at the end of a string results in the following assert error: auto m = match( "abc", "abc(.*)" ); writefln( "'%s'", m.captures[1] ); -> core.exception.AssertError@c:\dmd2\windows\bin\..\..\src\phobos\std\regex.d(1705): 1 In Captures.length : @property size_t length() { foreach (i; 0 .. matches.length) { if (matches[i].startIdx >= input.length) return i; } return matches.length; } The test will fail for an empty capture at the end because startIdx == endIdx == input.length. This seems like it should be a valid case and the following change seems to resolve the issue: if (matches[i].startIdx > input.length) return i;
Comment #1 by braddr — 2011-02-06T15:39:15Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #2 by dmitry.olsh — 2011-06-06T08:18:29Z
*** This issue has been marked as a duplicate of issue 5511 ***