Bug 19979 – std.regex should return null instead of zero-length slice for non-matched captures

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-17T20:41:05Z
Last change time
2019-07-04T16:04:27Z
Keywords
pull
Assigned to
No Owner
Creator
Vladimir Panteleev

Comments

Comment #0 by dlang-bugzilla — 2019-06-17T20:41:05Z
Consider this D program: void main() { auto m = matchFirst("bad", `^(?P<negation>not )?bad$`); assert(m); assert(!m["negation"]); } Currently, the assertion will fail, even though the capture "negation" was not found in the sought string. Ideally, std.regex would return "null" in this circumstance. (Currently, it returns input[0..0], which is a true-ish value.)
Comment #1 by dlang-bot — 2019-06-17T21:20:25Z
@CyberShadow created dlang/phobos pull request #7076 "Fix Issue 19979 - std.regex should return null for non-matched captures" fixing this issue: - Fix Issue 19979 - std.regex should return null for non-matched captures https://github.com/dlang/phobos/pull/7076
Comment #2 by dlang-bot — 2019-07-04T16:04:27Z
dlang/phobos pull request #7076 "Fix Issue 19979 - std.regex should return null instead of zero-length slice for non-matched captures" was merged into master: - 6c5d7230bcf0bf7f00fcc71d775175bfbba0e456 by Vladimir Panteleev: Fix Issue 19979 - std.regex should return null for non-matched captures https://github.com/dlang/phobos/pull/7076