Bug 19020 – findSkip, findSplit and findSplitBefore return wrong results

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-24T09:37:55Z
Last change time
2018-06-30T20:08:21Z
Keywords
pull
Assigned to
ag0aep6g
Creator
Jérôme Richard

Comments

Comment #0 by jeromerichard111 — 2018-06-24T09:37:55Z
findSkip does not check properly the end of searched ranges: it wrongly assumes that if the beginning of the needle string is found at the end of the haystack string, the whole needle string is found. The following code return true while s does not contain the substring "*/". Note that the code works well without a wrapper range (findSkip call findSplit which uses another implementation in this case). At first glance, the issue seems to come from the line "if (parts[1].empty) return false; // found" in the implementation: parts[1], returned by findSplit, can contain just a part of the whole needle string. However, the documentation of findSplit say that "If needle was not found, result[0] comprehends haystack entirely and result[1] and result[2] are empty." which is wrong here. Moreover, why findSkip does not use rather findSplitAfter? Also note that findSplitBefore is also as wrong as findSplit is the current implementation in this case (but findSplitAfter is OK). import std.stdio; import std.algorithm.searching; import std.string; import std.range; import std.conv; void main() { string s = "there is a bug here: *"; struct WrapperRange(R) { private R _r; this(R r) { _r = r; } @property auto empty() { return _r.empty(); } @property auto front() { return _r.front(); } auto popFront() { return _r.popFront(); } @property auto save() { return WrapperRange!R(_r.save); } } auto tmp = WrapperRange!string(s); writeln(tmp.findSkip("*/")); // true writeln("findSkip result: `", to!string(tmp), "`"); // findSkip result: `` }
Comment #1 by ag0aep6g — 2018-06-24T21:16:30Z
Comment #2 by github-bugzilla — 2018-06-30T20:08:17Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/93faca7ed52d117c70ce126e81e431712ab096b5 fix issue 19020 - findSkip, findSplit and findSplitBefore return wrong results https://github.com/dlang/phobos/commit/3c1a43e587078e4fb68bff06026ceb6f72c7d623 Merge pull request #6608 from aG0aep6G/findSplit fix findSplit and friends (issues 19020, 19023)