Skip to content

Commit ee716d6

Browse files
Tried to fix the version diff bug in 5540
1 parent f9812eb commit ee716d6

3 files changed

Lines changed: 45 additions & 7 deletions

File tree

src/AppInstallerCLITests/Versions.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,33 @@ TEST_CASE("OpenTypeFontVersion", "[versions]")
470470
REQUIRE(version.IsUnknown());
471471
REQUIRE(version.ToString() == "Unknown");
472472
}
473+
474+
TEST_CASE("VersionParseIgnoreParentheses", "[versions]")
475+
{
476+
// Test case for GitHub issue #5540
477+
// Version strings with parenthetical text should be treated the same as without
478+
Version versionWithParens("17.14.6 (June 2025)");
479+
Version versionWithoutParens("17.14.6");
480+
481+
// These should be considered equal for comparison purposes
482+
REQUIRE(versionWithParens == versionWithoutParens);
483+
REQUIRE_FALSE(versionWithParens < versionWithoutParens);
484+
REQUIRE_FALSE(versionWithParens > versionWithoutParens);
485+
486+
// Test VersionAndChannel comparison which is used in IsUpdatedBy
487+
VersionAndChannel versionWithParensVC(versionWithParens, Channel("");
488+
VersionAndChannel versionWithoutParensVC(versionWithoutParens, Channel("");
489+
490+
// Should not consider this an update
491+
REQUIRE_FALSE(versionWithParensVC.IsUpdatedBy(versionWithoutParensVC));
492+
REQUIRE_FALSE(versionWithoutParensVC.IsUpdatedBy(versionWithParensVC));
493+
494+
// Test with different formats of parenthetical text
495+
Version version1("1.2.3 (Build 456)");
496+
Version version2("1.2.3");
497+
Version version3("1.2.3 (Release)");
498+
499+
REQUIRE(version1 == version2);
500+
REQUIRE(version2 == version3);
501+
REQUIRE(version1 == version3);
502+
}

src/AppInstallerSharedLib/Versions.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,18 @@ namespace AppInstaller::Utility
279279
// Only true if this is less than, other is not, OR this is none, other is greater than
280280
return (m_approximateComparator == ApproximateComparator::LessThan && other.m_approximateComparator != ApproximateComparator::LessThan) ||
281281
(m_approximateComparator == ApproximateComparator::None && other.m_approximateComparator == ApproximateComparator::GreaterThan);
282-
}
283-
284-
Version::Part::Part(const std::string& part)
282+
} Version::Part::Part(const std::string& part)
285283
{
286284
std::string interimPart = Utility::Trim(part.c_str());
285+
286+
// Strip parenthetical text for version comparison
287+
// e.g., "17.14.6 (June 2025)" becomes "17.14.6"
288+
size_t parenPos = interimPart.find('(');
289+
if (parenPos != std::string::npos)
290+
{
291+
interimPart = Utility::Trim(interimPart.substr(0, parenPos));
292+
}
293+
287294
const char* begin = interimPart.c_str();
288295
char* end = nullptr;
289296
errno = 0;

src/Microsoft.Management.Deployment/CatalogPackage.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
6767

6868
void CatalogPackage::InitializeDefaultInstallVersion()
6969
{
70-
std::call_once(m_defaultInstallVersionOnceFlag,
71-
[&]()
70+
std::call_once(m_defaultInstallVersionOnceFlag, [&]()
7271
{
7372
using namespace AppInstaller::Pinning;
7473

@@ -77,10 +76,12 @@ namespace winrt::Microsoft::Management::Deployment::implementation
7776

7877
std::shared_ptr<::AppInstaller::Repository::IPackageVersion> latestVersion =
7978
evaluator.GetLatestAvailableVersionForPins(::AppInstaller::Repository::GetAvailableVersionsForInstalledVersion(m_package));
79+
80+
// Always set m_updateAvailable, regardless of whether latestVersion is null
81+
m_updateAvailable = latestVersion && evaluator.IsUpdate(latestVersion);
82+
8083
if (latestVersion)
8184
{
82-
m_updateAvailable = evaluator.IsUpdate(latestVersion);
83-
8485
// DefaultInstallVersion hasn't been created yet, create and populate it.
8586
// DefaultInstallVersion is the LatestAvailableVersion of the internal package object.
8687
auto latestVersionImpl = winrt::make_self<wil::details::module_count_wrapper<

0 commit comments

Comments
 (0)