Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,9 @@
<CopyFileToFolders Include="TestData\Manifest-Good-DefaultExpectedReturnCodeInInstallerSuccessCodes.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-InstallerUrl-BlockScalar.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-MultipleArpVersionDeclared.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@
<CopyFileToFolders Include="TestData\Manifest-Good-DefaultExpectedReturnCodeInInstallerSuccessCodes.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-InstallerUrl-BlockScalar.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\Manifest-Good-InstallerTypeExeRoot-Silent.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# yaml-language-server: $schema=https://aka.ms/winget-manifest.singleton.1.1.0.schema.json

PackageIdentifier: microsoft.msixsdk
PackageName: MSIX SDK
PackageVersion: 1.07.32-beta
Publisher: Microsoft
ShortDescription: description
License: Test
PackageLocale: en-US
Installers:
- Architecture: x86
InstallerUrl: >
https://ThisIsNotUsed
InstallerSha256: 98B67758CEAFFCBB3FE47838FD0A8D7BD581C2650842D6B2B0E0D49A23270CCD
InstallerType: msi
ManifestType: singleton
ManifestVersion: 1.1.0
10 changes: 10 additions & 0 deletions src/AppInstallerCLITests/YamlManifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,15 @@ TEST_CASE("ReadGoodManifestWithSpaces", "[ManifestValidation]")
REQUIRE(manifest.DefaultInstallerInfo.FileExtensions == MultiValue{ "appx", "appxbundle", "msix", "msixbundle" });
}

TEST_CASE("ReadGoodManifestInstallerUrlBlockScalar", "[ManifestValidation]")
{
ManifestValidateOption validateOption = GetTestManifestValidateOption();
Manifest manifest = YamlParser::CreateFromPath(TestDataFile("Manifest-Good-InstallerUrl-BlockScalar.yaml"), validateOption);

REQUIRE(manifest.Installers.size() == 1);
REQUIRE(manifest.Installers[0].Url == "https://ThisIsNotUsed\n");
}

TEST_CASE("ReadGoodManifests", "[ManifestValidation]")
{
ManifestTestCase TestCases[] =
Expand All @@ -973,6 +982,7 @@ TEST_CASE("ReadGoodManifests", "[ManifestValidation]")
{ "Manifest-Good-Minimum-InstallerType.yaml" },
{ "Manifest-Good-Switches.yaml" },
{ "Manifest-Good-DefaultExpectedReturnCodeInInstallerSuccessCodes.yaml" },
{ "Manifest-Good-InstallerUrl-BlockScalar.yaml" },
{ "Manifest-Good-InstallerTypeZip-PortableExe.yaml" },
{ "Manifest-Good-InstallerTypeZip-PortableExeUppercase.yaml" },
};
Expand Down
25 changes: 23 additions & 2 deletions src/AppInstallerSharedLib/JsonSchemaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@
#include "winget/JsonSchemaValidation.h"
#include "winget/Resources.h"

#include <regex>

namespace AppInstaller::JsonSchema
{
namespace
{
struct MultilineRegexEngine
{
explicit MultilineRegexEngine(const std::string& pattern) :
Regex(pattern, std::regex_constants::ECMAScript | std::regex_constants::multiline)
{
}

static bool search(const std::string& target, const MultilineRegexEngine& expression)
{
return std::regex_search(target, expression.Regex);
}

private:
std::regex Regex;
};
}

Json::Value LoadSchemaDoc(std::string_view schemaStr)
{
Json::Value schemaJson;
Expand Down Expand Up @@ -35,7 +56,7 @@ namespace AppInstaller::JsonSchema

bool Validate(const valijson::Schema& schema, const Json::Value& json, valijson::ValidationResults& results)
{
valijson::Validator schemaValidator;
valijson::ValidatorT<MultilineRegexEngine> schemaValidator;
valijson::adapters::JsonCppAdapter jsonAdapter(json);
return schemaValidator.validate(schema, jsonAdapter, &results);
}
Expand All @@ -59,4 +80,4 @@ namespace AppInstaller::JsonSchema

return ss.str();
}
}
}
Loading