commit d6a2f4c3cd7c72d4b15af529418717ab268ae118
parent 2f7f20dd134e90905e4e97f7b900ccff500e3685
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date: Wed, 3 Nov 2021 17:58:46 -0700
Fix incorrect processing of PackageMatchFields in rest client (#1659)
Diffstat:
4 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt
@@ -326,6 +326,7 @@ nonexistentsetting
NONINFRINGEMENT
norestart
normalizednameandpublisher
+normalizedpackagenameandpublisher
NOTHROW
NOTIMPL
NOTNULL
@@ -352,6 +353,8 @@ OUTOFDISKSPACE
OUTOFMEMORY
OWC
packagefamilyname
+packageidentifier
+packagename
PACKAGESSCHEMA
Params
params
diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp b/src/AppInstallerRepositoryCore/Rest/Schema/1_0/Json/SearchRequestSerializer_1_0.cpp
@@ -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)
{
diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/Interface.h
@@ -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;
};
diff --git a/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp b/src/AppInstallerRepositoryCore/Rest/Schema/1_1/RestInterface_1_1.cpp
@@ -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; }))
{
@@ -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)
{
@@ -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; }))
@@ -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;
+ }
}