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

Treat manifest localization validation error as warning for non full validation(manifest reading) #2144

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions src/AppInstallerCLITests/YamlManifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,4 +818,22 @@ TEST_CASE("ManifestApplyLocale", "[ManifestValidation]")
REQUIRE(manifest.CurrentLocalization.Locale == "fr-FR");
REQUIRE(manifest.CurrentLocalization.Get<Localization::PackageName>() == "fr-FR package name");
REQUIRE(manifest.CurrentLocalization.Get<Localization::Publisher>() == "es-MX publisher");
}

TEST_CASE("ManifestLocalizationValidation", "[ManifestValidation]")
{
Manifest manifest = YamlParser::CreateFromPath(TestDataFile("Manifest-Good-MultiLocale.yaml"));

// Set 1 locale to bad value
manifest.Localizations.at(0).Locale = "Invalid";

// Full validation should detect as error
auto errors = ValidateManifest(manifest, true);
REQUIRE(errors.size() == 1);
REQUIRE(errors.at(0).ErrorLevel == ValidationError::Level::Error);

// Not full validation should detect as warning
errors = ValidateManifest(manifest, false);
REQUIRE(errors.size() == 1);
REQUIRE(errors.at(0).ErrorLevel == ValidationError::Level::Warning);
}
8 changes: 4 additions & 4 deletions src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,20 @@ namespace AppInstaller::Manifest
// Validate localizations
for (auto const& localization : manifest.Localizations)
{
auto locErrors = ValidateManifestLocalization(localization);
auto locErrors = ValidateManifestLocalization(localization, !fullValidation);
std::move(locErrors.begin(), locErrors.end(), std::inserter(resultErrors, resultErrors.end()));
}

return resultErrors;
}

std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization)
std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization, bool treatErrorAsWarning)
{
std::vector<ValidationError> resultErrors;

if (!localization.Locale.empty() && !Locale::IsWellFormedBcp47Tag(localization.Locale))
{
resultErrors.emplace_back(ManifestError::InvalidBcp47Value, "PackageLocale", localization.Locale);
resultErrors.emplace_back(ManifestError::InvalidBcp47Value, "PackageLocale", localization.Locale, treatErrorAsWarning ? ValidationError::Level::Warning : ValidationError::Level::Error);
}

if (localization.Contains(Localization::Agreements))
Expand All @@ -227,7 +227,7 @@ namespace AppInstaller::Manifest
// At least one must be present
if (agreement.Label.empty() && agreement.AgreementText.empty() && agreement.AgreementUrl.empty())
{
resultErrors.emplace_back(ManifestError::InvalidFieldValue, "Agreements");
resultErrors.emplace_back(ManifestError::InvalidFieldValue, "Agreements", treatErrorAsWarning ? ValidationError::Level::Warning : ValidationError::Level::Error);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,18 @@ namespace AppInstaller::Manifest
ValidationError(std::string message, std::string field) :
Message(std::move(message)), Field(std::move(field)) {}

ValidationError(std::string message, std::string field, Level level) :
Message(std::move(message)), Field(std::move(field)), ErrorLevel(level) {}

ValidationError(std::string message, std::string field, std::string_view value) :
Message(std::move(message)), Field(std::move(field)), Value(value) {}

ValidationError(std::string message, std::string field, std::string value) :
Message(std::move(message)), Field(std::move(field)), Value(std::move(value)) {}

ValidationError(std::string message, std::string field, std::string value, Level level) :
Message(std::move(message)), Field(std::move(field)), Value(std::move(value)), ErrorLevel(level) {}

ValidationError(std::string message, std::string field, std::string value, size_t line, size_t column) :
Message(std::move(message)), Field(std::move(field)), Value(std::move(value)), Line(line), Column(column) {}

Expand Down Expand Up @@ -207,5 +213,5 @@ namespace AppInstaller::Manifest

// fullValidation: bool to set if manifest validation should perform extra validation that is not required for reading a manifest.
std::vector<ValidationError> ValidateManifest(const Manifest& manifest, bool fullValidation = true);
std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization);
std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization, bool treatErrorAsWarning = false);
}