mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Improve fs::PathStartsWith to handle empty strings (#14877)
`""` does not refer to a proper path, and `fs::PathStartsWith(path, "")` should just return `false`. This is also the case in libraries in other languages where I looked, seems to be common. The new behavior: * check early, if `prefix` is empty - return if path is empty or not, * no special processing for when `path` is empty, the function meets characters in `prefix` and returns false anyway.
This commit is contained in:
parent
5b19d315b3
commit
cfa9c83d33
2 changed files with 23 additions and 11 deletions
|
@ -113,6 +113,7 @@ void TestFileSys::testPathStartsWith()
|
|||
};
|
||||
/*
|
||||
expected fs::PathStartsWith results
|
||||
(row for every path, column for every prefix)
|
||||
0 = returns false
|
||||
1 = returns true
|
||||
2 = returns false on windows, true elsewhere
|
||||
|
@ -122,17 +123,17 @@ void TestFileSys::testPathStartsWith()
|
|||
*/
|
||||
int expected_results[numpaths][numpaths] = {
|
||||
{1,2,0,0,0,0,0,0,0,0,0,0},
|
||||
{1,1,0,0,0,0,0,0,0,0,0,0},
|
||||
{1,1,1,0,0,0,0,0,0,0,0,0},
|
||||
{1,1,1,1,0,0,0,0,0,0,0,0},
|
||||
{1,1,0,0,1,0,0,0,0,0,0,0},
|
||||
{1,1,0,0,0,1,0,0,1,1,0,0},
|
||||
{1,1,0,0,0,0,1,4,1,0,0,0},
|
||||
{1,1,0,0,0,0,4,1,4,0,0,0},
|
||||
{1,1,0,0,0,0,0,0,1,0,0,0},
|
||||
{1,1,0,0,0,0,0,0,1,1,0,0},
|
||||
{1,1,0,0,0,0,0,0,0,0,1,0},
|
||||
{1,1,0,0,0,0,0,0,0,0,0,1},
|
||||
{0,1,0,0,0,0,0,0,0,0,0,0},
|
||||
{0,1,1,0,0,0,0,0,0,0,0,0},
|
||||
{0,1,1,1,0,0,0,0,0,0,0,0},
|
||||
{0,1,0,0,1,0,0,0,0,0,0,0},
|
||||
{0,1,0,0,0,1,0,0,1,1,0,0},
|
||||
{0,1,0,0,0,0,1,4,1,0,0,0},
|
||||
{0,1,0,0,0,0,4,1,4,0,0,0},
|
||||
{0,1,0,0,0,0,0,0,1,0,0,0},
|
||||
{0,1,0,0,0,0,0,0,1,1,0,0},
|
||||
{0,1,0,0,0,0,0,0,0,0,1,0},
|
||||
{0,1,0,0,0,0,0,0,0,0,0,1},
|
||||
};
|
||||
|
||||
for (int i = 0; i < numpaths; i++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue