Skip to content

Commit 4e6336a

Browse files
authored
Don't rely on parameter order when creating VersionRange (#5226)
Instead of relying on the parameters to be in the correct order for minimum and maximum when creating a VersionRange, the code can instead just put them in the right order. CP from #5213
1 parent b90caae commit 4e6336a

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/AppInstallerCLITests/Versions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ TEST_CASE("VersionRange", "[versions]")
373373
// Create
374374
REQUIRE_NOTHROW(VersionRange{ Version{ "1.0" }, Version{ "2.0" } });
375375
REQUIRE_NOTHROW(VersionRange{ Version{ "1.0" }, Version{ "1.0" } });
376-
REQUIRE_THROWS(VersionRange{ Version{ "2.0" }, Version{ "1.0" } });
376+
REQUIRE_NOTHROW(VersionRange{ Version{ "2.0" }, Version{ "1.0" } });
377377

378378
// Overlaps
379379
REQUIRE(VersionRange{ Version{ "1.0" }, Version{ "2.0" } }.Overlaps(VersionRange{ Version{ "2.0" }, Version{ "3.0" } }));

src/AppInstallerSharedLib/Versions.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,18 @@ namespace AppInstaller::Utility
533533
return m_buildMetadata;
534534
}
535535

536-
VersionRange::VersionRange(Version minVersion, Version maxVersion)
536+
VersionRange::VersionRange(Version first, Version second)
537537
{
538-
THROW_HR_IF(E_INVALIDARG, minVersion > maxVersion);
539-
m_minVersion = std::move(minVersion);
540-
m_maxVersion = std::move(maxVersion);
538+
if (first < second)
539+
{
540+
m_minVersion = std::move(first);
541+
m_maxVersion = std::move(second);
542+
}
543+
else
544+
{
545+
m_minVersion = std::move(second);
546+
m_maxVersion = std::move(first);
547+
}
541548
}
542549

543550
bool VersionRange::Overlaps(const VersionRange& other) const

0 commit comments

Comments
 (0)