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 all commits
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
13 changes: 7 additions & 6 deletions src/AppInstallerSharedLib/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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