Skip to content

Commit 866c5f4

Browse files
authored
Fix issue when two filter "excludes" have the same string length (#22)
1 parent 49399fb commit 866c5f4

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/impl/winmd_reader/filter.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ namespace winmd::reader
2020

2121
std::sort(m_rules.begin(), m_rules.end(), [](auto const& lhs, auto const& rhs)
2222
{
23-
auto size_compare = int(lhs.first.size()) - int(rhs.first.size());
24-
return (size_compare > 0) || ((size_compare == 0) && !lhs.second);
23+
return std::pair{ lhs.first.size(), lhs.second } > std::pair{ rhs.first.size(), rhs.second };
2524
});
2625
}
2726

test/filter.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "pch.h"
2+
#include <winmd_reader.h>
3+
4+
using namespace winmd::reader;
5+
6+
TEST_CASE("filter_simple")
7+
{
8+
std::vector<std::string> include = { "N1", "N3", "N3.N4.N5" };
9+
std::vector<std::string> exclude = { "N2", "N3.N4" };
10+
11+
filter f{ include, exclude };
12+
13+
REQUIRE(!f.empty());
14+
15+
REQUIRE(!f.includes("NN.T"));
16+
17+
REQUIRE(f.includes("N1.T"));
18+
REQUIRE(f.includes("N3.T"));
19+
20+
REQUIRE(!f.includes("N2.T"));
21+
REQUIRE(!f.includes("N3.N4.T"));
22+
23+
REQUIRE(f.includes("N3.N4.N5.T"));
24+
}
25+
26+
TEST_CASE("filter_excludes_same_length")
27+
{
28+
std::vector<std::string> include = { "N.N1", "N.N2" };
29+
std::vector<std::string> exclude = { "N.N3", "N.N4" };
30+
31+
filter f{ include, exclude };
32+
33+
REQUIRE(!f.empty());
34+
35+
REQUIRE(f.includes("N.N1.T"));
36+
REQUIRE(f.includes("N.N2.T"));
37+
38+
REQUIRE(!f.includes("N.N3.T"));
39+
REQUIRE(!f.includes("N.N4.T"));
40+
}

test/winmd.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<ItemGroup>
2222
<ClCompile Include="cache.cpp" />
2323
<ClCompile Include="database.cpp" />
24+
<ClCompile Include="filter.cpp" />
2425
<ClCompile Include="main.cpp">
2526
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
2627
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>

0 commit comments

Comments
 (0)