Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim Version When Parsing #4554

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/AppInstallerSharedLib/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace AppInstaller::Utility

Version::Version(std::string&& version, std::string_view splitChars)
{
Assign(std::move(version), splitChars);
Assign(std::move(Utility::Trim(version)), splitChars);
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}

Version::Version(Version baseVersion, ApproximateComparator approximateComparator) : Version(std::move(baseVersion))
Expand All @@ -41,7 +41,7 @@ namespace AppInstaller::Utility

void Version::Assign(std::string version, std::string_view splitChars)
{
m_version = std::move(version);
m_version = std::move(Utility::Trim(version));

// Process approximate comparator if applicable
std::string baseVersion = m_version;
Expand Down Expand Up @@ -281,17 +281,18 @@ namespace AppInstaller::Utility

Version::Part::Part(const std::string& part)
{
const char* begin = part.c_str();
std::string interimPart = Utility::Trim(part.c_str());
const char* begin = interimPart.c_str();
char* end = nullptr;
errno = 0;
Integer = strtoull(begin, &end, 10);

if (errno == ERANGE)
{
Integer = 0;
Other = part;
Other = interimPart;
}
else if (static_cast<size_t>(end - begin) != part.length())
else if (static_cast<size_t>(end - begin) != interimPart.length())
{
Other = end;
}
Expand All @@ -300,7 +301,7 @@ namespace AppInstaller::Utility
}

Version::Part::Part(uint64_t integer, std::string other) :
Integer(integer), Other(std::move(other))
Integer(integer), Other(std::move(Utility::Trim(other)))
{
m_foldedOther = Utility::FoldCase(static_cast<std::string_view>(Other));
}
Expand Down Expand Up @@ -437,12 +438,12 @@ namespace AppInstaller::Utility

UInt64Version::UInt64Version(std::string&& version, std::string_view splitChars)
{
Assign(std::move(version), splitChars);
Assign(std::move(Utility::Trim(version)), splitChars);
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}

void UInt64Version::Assign(std::string version, std::string_view splitChars)
{
Version::Assign(std::move(version), splitChars);
Version::Assign(std::move(Utility::Trim(version)), splitChars);
Trenly marked this conversation as resolved.
Show resolved Hide resolved

// After trimming trailing parts (0 or empty),
// at most 4 parts must be present
Expand All @@ -459,7 +460,7 @@ namespace AppInstaller::Utility

SemanticVersion::SemanticVersion(std::string&& version)
{
Assign(std::move(version), DefaultSplitChars);
Assign(std::move(Utility::Trim(version)), DefaultSplitChars);
Trenly marked this conversation as resolved.
Show resolved Hide resolved
}

void SemanticVersion::Assign(std::string version, std::string_view splitChars)
Expand All @@ -468,7 +469,7 @@ namespace AppInstaller::Utility
THROW_HR_IF(E_INVALIDARG, splitChars != DefaultSplitChars);

// First split off any trailing build metadata
std::string interimVersion = version;
std::string interimVersion = Utility::Trim(version);
size_t buildMetadataPos = interimVersion.find('+', 0);

if (buildMetadataPos != std::string::npos)
Expand Down
Loading