Skip to content

Commit d348e51

Browse files
authored
fix: startsWith function respects path separators
1 parent 3ff3744 commit d348e51

File tree

14 files changed

+265
-1
lines changed

14 files changed

+265
-1
lines changed

src/lib/Support/Path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ startsWith(
475475
++itPrefix;
476476
}
477477
// Have we consumed the whole prefix?
478-
return itPrefix == prefix.end();
478+
return itPrefix == prefix.end() && (itPath == pathName.end() || *itPath == '/' || *itPath == '\\');
479479
}
480480

481481
} // files

src/test/lib/Support/Path.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,45 @@ struct Path_test
2929
*/
3030
}
3131

32+
void
33+
testStartsWith()
34+
{
35+
using namespace files;
36+
37+
// empty
38+
{
39+
BOOST_TEST(startsWith("", ""));
40+
}
41+
42+
// identical
43+
{
44+
BOOST_TEST(startsWith("/", "/"));
45+
BOOST_TEST(startsWith("/abc", "/abc"));
46+
BOOST_TEST(startsWith("/abc/def", "/abc/def"));
47+
}
48+
49+
// equivalent
50+
{
51+
BOOST_TEST(startsWith("/", "\\"));
52+
BOOST_TEST(startsWith("/abc", "\\abc"));
53+
BOOST_TEST(startsWith("\\abc", "/abc"));
54+
BOOST_TEST(startsWith("/abc/def", "\\abc\\def"));
55+
BOOST_TEST(startsWith("\\abc\\def", "/abc/def"));
56+
}
57+
58+
// subdirectory
59+
{
60+
BOOST_TEST(startsWith("/abc/def", "/abc"));
61+
BOOST_TEST(startsWith("\\abc\\def", "/abc"));
62+
BOOST_TEST_NOT(startsWith("/abcdef", "/abc"));
63+
BOOST_TEST_NOT(startsWith("\\abcdef", "/abc"));
64+
}
65+
}
66+
3267
void run()
3368
{
3469
testPaths();
70+
testStartsWith();
3571
}
3672
};
3773

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** A brief.
2+
*/
3+
4+
void f();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** A brief.
2+
*/
3+
4+
void g();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Functions
8+
9+
[cols=2]
10+
|===
11+
| Name
12+
| Description
13+
| link:#f[`f`]
14+
| A brief.
15+
|===
16+
17+
[#f]
18+
== f
19+
20+
A brief.
21+
22+
=== Synopsis
23+
24+
Declared in `<a/included.hpp>`
25+
26+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
27+
----
28+
void
29+
f();
30+
----
31+
32+
33+
[.small]#Created with https://www.mrdocs.com[MrDocs]#
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "a/included.hpp"
2+
#include "abc/excluded.hpp"
3+
4+
namespace TEST
5+
{
6+
struct SUCCESS {};
7+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<html lang="en">
2+
<head>
3+
<title>Reference</title>
4+
</head>
5+
<body>
6+
<div>
7+
<h1>Reference</h1>
8+
<div>
9+
<div>
10+
<h2 id="index"><a href="#index"></a></h2>
11+
</div>
12+
<h2>Functions</h2>
13+
<table style="table-layout: fixed; width: 100%;">
14+
<thead>
15+
<tr>
16+
<th>Name</th>
17+
<th>Description</th>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
<tr>
22+
<td><a href="#f"><code>f</code></a> </td><td><span>A brief.</span></td></tr>
23+
</tbody>
24+
</table>
25+
26+
</div>
27+
<div>
28+
<div>
29+
<h2 id="f"><a href="#f">f</a></h2>
30+
<div>
31+
<span>A brief.</span>
32+
33+
</div>
34+
</div>
35+
<div>
36+
<h3>Synopsis</h3>
37+
<div>
38+
Declared in <code>&lt;a/included.hpp&gt;</code></div>
39+
<pre>
40+
<code class="source-code cpp">void
41+
f();
42+
43+
</code>
44+
</pre>
45+
</div>
46+
</div>
47+
48+
</div>
49+
<div>
50+
<h4>Created with <a href="https://www.mrdocs.com">MrDocs</a></h4>
51+
</div>
52+
</body>
53+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mrdocs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://github.com/cppalliance/mrdocs/raw/develop/mrdocs.rnc">
4+
<namespace id="//////////////////////////8=">
5+
<function name="f" id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
6+
<file short-path="a/included.hpp" source-path="a/included.hpp" line="4"/>
7+
<doc>
8+
<brief>
9+
<text>A brief.</text>
10+
</brief>
11+
</doc>
12+
</function>
13+
</namespace>
14+
</mrdocs>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Include a (but not abc)
2+
input:
3+
- './a/'
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
= Reference
2+
:mrdocs:
3+
4+
[#index]
5+
== Global namespace
6+
7+
=== Functions
8+
9+
[cols=2]
10+
|===
11+
| Name
12+
| Description
13+
| link:#f[`f`]
14+
| A brief&period;
15+
|===
16+
17+
[#f]
18+
== f
19+
20+
A brief&period;
21+
22+
=== Synopsis
23+
24+
Declared in `&lt;a&sol;included&period;hpp&gt;`
25+
26+
[source,cpp,subs="verbatim,replacements,macros,-callouts"]
27+
----
28+
void
29+
f();
30+
----
31+
32+
33+
[.small]#Created with https://www.mrdocs.com[MrDocs]#

0 commit comments

Comments
 (0)