Skip to content

Commit

Permalink
Fix incorrect processing of PackageMatchFields in rest client (#1659)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft committed Nov 4, 2021
1 parent 2f7f20d commit d6a2f4c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ nonexistentsetting
NONINFRINGEMENT
norestart
normalizednameandpublisher
normalizedpackagenameandpublisher
NOTHROW
NOTIMPL
NOTNULL
Expand All @@ -352,6 +353,8 @@ OUTOFDISKSPACE
OUTOFMEMORY
OWC
packagefamilyname
packageidentifier
packagename
PACKAGESSCHEMA
Params
params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_0::Json
}

filter[JsonHelper::GetUtilityString(PackageMatchField)] = web::json::value::string(JsonHelper::GetUtilityString(matchField.value()));
AppInstaller::Repository::RequestMatch requestMatch{ packageMatchFilter.Type, packageMatchFilter.Value };
std::optional<web::json::value> requestMatchJson = GetRequestMatchJsonObject(requestMatch);
std::optional<web::json::value> requestMatchJson = GetRequestMatchJsonObject(packageMatchFilter);

if (!requestMatchJson)
{
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1
SearchResult GetSearchResult(const web::json::value& searchResponseObject) const override;
std::vector<Manifest::Manifest> GetParsedManifests(const web::json::value& manifestsResponseObject) const override;

PackageMatchField ConvertStringToPackageMatchField(std::string_view field) const;

private:
IRestClient::Information m_information;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1

for (auto const& field : m_information.RequiredPackageMatchFields)
{
PackageMatchField matchField = StringToPackageMatchField(field);
PackageMatchField matchField = ConvertStringToPackageMatchField(field);

if (searchRequest.Filters.end() == std::find_if(searchRequest.Filters.begin(), searchRequest.Filters.end(), [&](const PackageMatchFilter& filter) { return filter.Field == matchField; }))
{
Expand All @@ -105,7 +105,7 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1

for (auto const& field : m_information.UnsupportedPackageMatchFields)
{
PackageMatchField matchField = StringToPackageMatchField(field);
PackageMatchField matchField = ConvertStringToPackageMatchField(field);

if (matchField == PackageMatchField::Unknown)
{
Expand All @@ -116,8 +116,11 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1
{
AICLI_LOG(Repo, Info, << "Search request Inclusions contains package match field not supported by the rest source. Ignoring the field. Unsupported package match field: " << field);

auto itr = std::find_if(resultSearchRequest.Inclusions.begin(), resultSearchRequest.Inclusions.end(), [&](const PackageMatchFilter& inclusion) { return inclusion.Field == matchField; });
resultSearchRequest.Inclusions.erase(itr);
resultSearchRequest.Inclusions.erase(
std::remove_if(
resultSearchRequest.Inclusions.begin(), resultSearchRequest.Inclusions.end(),
[&](const PackageMatchFilter& inclusion) { return inclusion.Field == matchField; }),
resultSearchRequest.Inclusions.end());
}

if (searchRequest.Filters.end() != std::find_if(searchRequest.Filters.begin(), searchRequest.Filters.end(), [&](const PackageMatchFilter& filter) { return filter.Field == matchField; }))
Expand Down Expand Up @@ -169,4 +172,48 @@ namespace AppInstaller::Repository::Rest::Schema::V1_1

return result;
}

PackageMatchField Interface::ConvertStringToPackageMatchField(std::string_view field) const
{
std::string toLower = Utility::ToLower(field);

if (toLower == "command")
{
return PackageMatchField::Command;
}
else if (toLower == "packageidentifier")
{
return PackageMatchField::Id;
}
else if (toLower == "moniker")
{
return PackageMatchField::Moniker;
}
else if (toLower == "packagename")
{
return PackageMatchField::Name;
}
else if (toLower == "tag")
{
return PackageMatchField::Tag;
}
else if (toLower == "packagefamilyname")
{
return PackageMatchField::PackageFamilyName;
}
else if (toLower == "productcode")
{
return PackageMatchField::ProductCode;
}
else if (toLower == "normalizedpackagenameandpublisher")
{
return PackageMatchField::NormalizedNameAndPublisher;
}
else if (toLower == "market")
{
return PackageMatchField::Market;
}

return PackageMatchField::Unknown;
}
}

0 comments on commit d6a2f4c

Please sign in to comment.