Skip to content

Commit

Permalink
Update valijson to v1.0.2 (#4588)
Browse files Browse the repository at this point in the history
Update valijson to v1.0.2 to have correct validation on date/datetime
formats.

Updated the test files with correct date time formats. Validated
previously generated export files have correct date time formats and the
new validation will not break existing exported files.

Updated project file to only include headers we directly reference so
that we don't need to maintain the list every time we do an update.
  • Loading branch information
yao-msft authored Jun 27, 2024
2 parents 015f0e9 + 798e928 commit 986f240
Show file tree
Hide file tree
Showing 472 changed files with 12,894 additions and 176,797 deletions.
2 changes: 1 addition & 1 deletion cgmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"type": "git",
"git": {
"repositoryUrl": "https://github.com/tristanpenman/valijson.git",
"commitHash": "2dfc7499a31b84edef71189f4247919268ebc74e"
"commitHash": "0b4771e273a065d437814baf426bcfcafec0f434"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand All @@ -18,4 +18,4 @@
}
],
"WinGetVersion": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
53 changes: 18 additions & 35 deletions src/AppInstallerCLITests/PackageCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,11 @@ namespace
}

REQUIRE(node.isMember(propertyName));
REQUIRE(node[propertyName].isString());
REQUIRE(node[propertyName].asString() == expectedValue);
}

void ValidateJsonStringPropertyRegex(const Json::Value& node, const std::string& propertyName, std::string_view regex, bool allowMissing = false)
{
if (allowMissing && !node.isMember(propertyName))
{
return;
REQUIRE(node[propertyName].isString());
if (!expectedValue.empty())
{
REQUIRE(node[propertyName].asString() == expectedValue);
}

REQUIRE(node.isMember(propertyName));
REQUIRE(node[propertyName].isString());
const auto& value = AppInstaller::Utility::ConvertToUTF16(node[propertyName].asString());
REQUIRE(AppInstaller::Regex::Expression(regex).IsMatch(value));
}

const Json::Value& GetAndValidateJsonProperty(const Json::Value& node, const std::string& propertyName, Json::ValueType valueType)
Expand All @@ -77,13 +67,8 @@ namespace
{
ValidateJsonStringProperty(root, s_PackagesJson_Schema, s_PackagesJson_SchemaUri_v2_0);
ValidateJsonStringProperty(root, s_PackagesJson_WinGetVersion, collection.ClientVersion);

// valijson does not validate the date-time format, which should follow RFC3339 according to the JSON schema.
// Ensure we write something at least reasonable.
// The expected format is <Date>T<Time><TimeZone>
// with Date="YYYY-MM-DD"; Time="HH:mm:ss.xxx"; TimeZone="Z" or "+HH:mm" or "-HH:mm" (offset from UTC)
std::string_view dateTimeRegex = "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+(Z|[+-][0-9]{2}:[0-9]{2})"sv;
ValidateJsonStringPropertyRegex(root, s_PackagesJson_CreationDate, dateTimeRegex);
// valijson now validates the date-time format, just check the string property exists.
ValidateJsonStringProperty(root, s_PackagesJson_CreationDate, "");

const auto& jsonSources = GetAndValidateJsonProperty(root, s_PackagesJson_Sources, Json::ValueType::arrayValue);
REQUIRE(jsonSources.size() == collection.Sources.size());
Expand Down Expand Up @@ -191,7 +176,7 @@ TEST_CASE("PackageCollection_Read_SingleSource_1_0", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down Expand Up @@ -242,7 +227,7 @@ TEST_CASE("PackageCollection_Read_SingleSource_2_0", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down Expand Up @@ -292,7 +277,7 @@ TEST_CASE("PackageCollection_Read_MultipleSources_1_0", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"WinGetVersion": "1.0.0",
"Sources": [
{
Expand Down Expand Up @@ -358,7 +343,7 @@ TEST_CASE("PackageCollection_Read_MultipleSources_2_0", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.2.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"WinGetVersion": "1.0.0",
"Sources": [
{
Expand Down Expand Up @@ -424,7 +409,7 @@ TEST_CASE("PackageCollection_Read_RepeatedSource", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"WinGetVersion": "1.0.0",
"Sources": [
{
Expand Down Expand Up @@ -504,7 +489,7 @@ TEST_CASE("PackageCollection_Read_MissingSchema", "[PackageCollection]")
{
auto json = ParseJsonString(R"(
{
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down Expand Up @@ -537,7 +522,7 @@ TEST_CASE("PackageCollection_Read_WrongSchema", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-settings.schema.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down Expand Up @@ -565,7 +550,7 @@ TEST_CASE("PackageCollection_Read_SchemaValidationFail", "[PackageCollection]")
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"NotSources": [
{
"Packages": [
Expand Down Expand Up @@ -596,7 +581,7 @@ TEST_CASE("PackageCollection_Read_SchemaValidationFail_Id", "[PackageCollection]
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down Expand Up @@ -624,8 +609,6 @@ TEST_CASE("PackageCollection_Read_SchemaValidationFail_Id", "[PackageCollection]

TEST_CASE("PackageCollection_Read_BadTimeStamp", "[PackageCollection]")
{
// We used to export without padding the creation date with 0s nor adding time zone.
// Ensure we don't break with that format.
auto json = ParseJsonString(R"(
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
Expand All @@ -651,6 +634,6 @@ TEST_CASE("PackageCollection_Read_BadTimeStamp", "[PackageCollection]")
auto parseResult = PackagesJson::TryParseJson(json);
INFO(parseResult.Errors);

REQUIRE(parseResult.Result == PackagesJson::ParseResult::Type::Success);
REQUIRE(parseResult.Errors.empty());
}
REQUIRE(parseResult.Result == PackagesJson::ParseResult::Type::SchemaValidationFailed);
REQUIRE_FALSE(parseResult.Errors.empty());
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand All @@ -18,4 +18,4 @@
}
],
"WinGetVersion": "1.0.0"
}
}
2 changes: 1 addition & 1 deletion src/AppInstallerCLITests/TestData/ImportFile-Good.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://aka.ms/winget-packages.schema.1.0.json",
"CreationDate": "2021-01-01T12:00:00.000",
"CreationDate": "2021-01-01T12:00:00.000-00:00",
"Sources": [
{
"Packages": [
Expand Down
35 changes: 0 additions & 35 deletions src/Valijson/Valijson.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,9 @@
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\basic_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\frozen_value.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\json11_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\jsoncpp_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\nlohmann_json_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\picojson_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\poco_json_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\property_tree_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\qtjson_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\rapidjson_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\adapters\std_string_adapter.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\constraints\basic_constraint.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\constraints\concrete_constraints.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\constraints\constraint.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\constraints\constraint_visitor.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\constraint_builder.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\custom_allocator.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\debug.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\json_pointer.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\json_reference.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\optional.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\internal\uri.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\schema.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\schema_parser.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\subschema.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\file_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\json11_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\jsoncpp_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\nlohmann_json_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\picojson_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\poco_json_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\property_tree_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\qtjson_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\rapidjson_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\utils\utf8_utils.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\validation_results.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\validation_visitor.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)valijson\include\valijson\validator.hpp" />
</ItemGroup>
</Project>
Loading

0 comments on commit 986f240

Please sign in to comment.