From 727a17482ef9a422fa4fc54179b64926356241eb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:31:33 +1000 Subject: [PATCH] Bump YamlDotNet from 15.3.0 to 16.0.0 (#1874) * Update to YamlDotNet v16.1.3 * Additional fixes --------- Co-authored-by: Bernie White --- docs/CHANGELOG-v3.md | 4 + src/PSRule.Benchmark/packages.lock.json | 6 +- src/PSRule.CommandLine/packages.lock.json | 6 +- src/PSRule.SDK/packages.lock.json | 6 +- src/PSRule.Tool/packages.lock.json | 6 +- .../Converters/Yaml/StringArrayConverter.cs | 4 +- .../Yaml/StringArrayMapConverter.cs | 4 +- src/PSRule.Types/PSRule.Types.csproj | 2 +- src/PSRule.Types/packages.lock.json | 6 +- src/PSRule/Common/YamlConverters.cs | 98 +++++++++++-------- src/PSRule/packages.lock.json | 6 +- 11 files changed, 82 insertions(+), 66 deletions(-) diff --git a/docs/CHANGELOG-v3.md b/docs/CHANGELOG-v3.md index f2c26d48e5..da74616281 100644 --- a/docs/CHANGELOG-v3.md +++ b/docs/CHANGELOG-v3.md @@ -27,6 +27,10 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers ## Unreleased +- Engineering: + - Bump YamlDotNet to v16.1.3. + [#1874](https://github.com/microsoft/PSRule/pull/1874) + ## v3.0.0-B0275 (pre-release) What's changed since pre-release v3.0.0-B0267: diff --git a/src/PSRule.Benchmark/packages.lock.json b/src/PSRule.Benchmark/packages.lock.json index f09ebaa60f..1015410736 100644 --- a/src/PSRule.Benchmark/packages.lock.json +++ b/src/PSRule.Benchmark/packages.lock.json @@ -1986,8 +1986,8 @@ }, "YamlDotNet": { "type": "Transitive", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.PSRule.Badges": { "type": "Project", @@ -2012,7 +2012,7 @@ "type": "Project", "dependencies": { "Newtonsoft.Json": "[13.0.3, )", - "YamlDotNet": "[15.3.0, )" + "YamlDotNet": "[16.1.3, )" } } } diff --git a/src/PSRule.CommandLine/packages.lock.json b/src/PSRule.CommandLine/packages.lock.json index cc26d35b8d..6806d6d45e 100644 --- a/src/PSRule.CommandLine/packages.lock.json +++ b/src/PSRule.CommandLine/packages.lock.json @@ -1635,8 +1635,8 @@ }, "YamlDotNet": { "type": "Transitive", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.PSRule.Badges": { "type": "Project", @@ -1667,7 +1667,7 @@ "type": "Project", "dependencies": { "Newtonsoft.Json": "[13.0.3, )", - "YamlDotNet": "[15.3.0, )" + "YamlDotNet": "[16.1.3, )" } } } diff --git a/src/PSRule.SDK/packages.lock.json b/src/PSRule.SDK/packages.lock.json index 6bcdbaad03..3191a3bc3e 100644 --- a/src/PSRule.SDK/packages.lock.json +++ b/src/PSRule.SDK/packages.lock.json @@ -1033,8 +1033,8 @@ }, "YamlDotNet": { "type": "Transitive", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.PSRule.Badges": { "type": "Project", @@ -1059,7 +1059,7 @@ "type": "Project", "dependencies": { "Newtonsoft.Json": "[13.0.3, )", - "YamlDotNet": "[15.3.0, )" + "YamlDotNet": "[16.1.3, )" } } } diff --git a/src/PSRule.Tool/packages.lock.json b/src/PSRule.Tool/packages.lock.json index b294f4828b..5f01594ce2 100644 --- a/src/PSRule.Tool/packages.lock.json +++ b/src/PSRule.Tool/packages.lock.json @@ -1632,8 +1632,8 @@ }, "YamlDotNet": { "type": "Transitive", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.PSRule.Badges": { "type": "Project", @@ -1673,7 +1673,7 @@ "type": "Project", "dependencies": { "Newtonsoft.Json": "[13.0.3, )", - "YamlDotNet": "[15.3.0, )" + "YamlDotNet": "[16.1.3, )" } } }, diff --git a/src/PSRule.Types/Converters/Yaml/StringArrayConverter.cs b/src/PSRule.Types/Converters/Yaml/StringArrayConverter.cs index bd098a3cb5..dd9f896566 100644 --- a/src/PSRule.Types/Converters/Yaml/StringArrayConverter.cs +++ b/src/PSRule.Types/Converters/Yaml/StringArrayConverter.cs @@ -19,7 +19,7 @@ bool IYamlTypeConverter.Accepts(Type type) } /// - object? IYamlTypeConverter.ReadYaml(IParser parser, Type type) + object? IYamlTypeConverter.ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { if (parser.TryConsume(out _)) { @@ -38,7 +38,7 @@ bool IYamlTypeConverter.Accepts(Type type) } /// - void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type) + void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { throw new NotImplementedException(); } diff --git a/src/PSRule.Types/Converters/Yaml/StringArrayMapConverter.cs b/src/PSRule.Types/Converters/Yaml/StringArrayMapConverter.cs index 60220c53c7..874158cb28 100644 --- a/src/PSRule.Types/Converters/Yaml/StringArrayMapConverter.cs +++ b/src/PSRule.Types/Converters/Yaml/StringArrayMapConverter.cs @@ -20,7 +20,7 @@ bool IYamlTypeConverter.Accepts(Type type) } /// - object? IYamlTypeConverter.ReadYaml(IParser parser, Type type) + object? IYamlTypeConverter.ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { var result = new StringArrayMap(); if (parser.TryConsume(out _)) @@ -56,7 +56,7 @@ bool IYamlTypeConverter.Accepts(Type type) } /// - void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type) + void IYamlTypeConverter.WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { if (type == typeof(StringArrayMap) && value == null) { diff --git a/src/PSRule.Types/PSRule.Types.csproj b/src/PSRule.Types/PSRule.Types.csproj index 6167b5d1ae..24813008a8 100644 --- a/src/PSRule.Types/PSRule.Types.csproj +++ b/src/PSRule.Types/PSRule.Types.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/PSRule.Types/packages.lock.json b/src/PSRule.Types/packages.lock.json index cd68d666ad..1b0292344c 100644 --- a/src/PSRule.Types/packages.lock.json +++ b/src/PSRule.Types/packages.lock.json @@ -35,9 +35,9 @@ }, "YamlDotNet": { "type": "Direct", - "requested": "[15.3.0, )", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "requested": "[16.1.3, )", + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.Build.Tasks.Git": { "type": "Transitive", diff --git a/src/PSRule/Common/YamlConverters.cs b/src/PSRule/Common/YamlConverters.cs index 9d549b8dc5..2dd9a66dfe 100644 --- a/src/PSRule/Common/YamlConverters.cs +++ b/src/PSRule/Common/YamlConverters.cs @@ -34,7 +34,7 @@ public bool Accepts(Type type) return type == typeof(SuppressionRule); } - public object? ReadYaml(IParser parser, Type type) + public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { var result = new SuppressionRule(); if (parser.TryConsume(out _)) @@ -66,7 +66,7 @@ public bool Accepts(Type type) return result; } - public void WriteYaml(IEmitter emitter, object? value, Type type) + public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { throw new NotImplementedException(); } @@ -82,7 +82,7 @@ public bool Accepts(Type type) return type == typeof(FieldMap); } - public object? ReadYaml(IParser parser, Type type) + public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { var result = new FieldMap(); if (parser.TryConsume(out _)) @@ -111,7 +111,7 @@ public bool Accepts(Type type) return result; } - public void WriteYaml(IEmitter emitter, object? value, Type type) + public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { if (type == typeof(FieldMap) && value == null) { @@ -146,7 +146,7 @@ public bool Accepts(Type type) return type == typeof(PSObject); } - public object? ReadYaml(IParser parser, Type type) + public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer) { // Handle empty objects if (parser.TryConsume(out var scalar) && scalar != null) @@ -161,7 +161,7 @@ public bool Accepts(Type type) while (parser.TryConsume(out scalar) && scalar != null) { var name = scalar.Value; - var property = ReadNoteProperty(parser, name) ?? throw new NotImplementedException(); + var property = ReadNoteProperty(parser, name, rootDeserializer) ?? throw new NotImplementedException(); result.Properties.Add(property); } #pragma warning restore @@ -171,12 +171,12 @@ public bool Accepts(Type type) return result; } - public void WriteYaml(IEmitter emitter, object? value, Type type) + public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { Map(emitter, value); } - private PSNoteProperty? ReadNoteProperty(IParser parser, string name) + private PSNoteProperty? ReadNoteProperty(IParser parser, string name, ObjectDeserializer rootDeserializer) { if (parser.TryConsume(out _)) { @@ -185,7 +185,7 @@ public void WriteYaml(IEmitter emitter, object? value, Type type) { if (parser.Current is MappingStart) { - values.Add(PSObject.AsPSObject(ReadYaml(parser, typeof(PSObject)))); + values.Add(PSObject.AsPSObject(ReadYaml(parser, typeof(PSObject), rootDeserializer))); } else if (parser.TryConsume(out var scalar)) { @@ -198,7 +198,7 @@ public void WriteYaml(IEmitter emitter, object? value, Type type) } else if (parser.Current is MappingStart) { - return new PSNoteProperty(name, ReadYaml(parser, typeof(PSObject))); + return new PSNoteProperty(name, ReadYaml(parser, typeof(PSObject), rootDeserializer)); } else if (parser.TryConsume(out var scalar)) { @@ -310,7 +310,7 @@ public bool Resolve(NodeEvent? nodeEvent, ref Type currentType) /// /// A YAML type inspector to order properties alphabetically /// -internal sealed class OrderedPropertiesTypeInspector(ITypeInspector innerTypeDescriptor) : TypeInspectorSkeleton +internal sealed class OrderedPropertiesTypeInspector(ITypeInspector innerTypeDescriptor) : ReflectionTypeInspector { public override IEnumerable GetProperties(Type type, object? container) { @@ -323,7 +323,7 @@ public override IEnumerable GetProperties(Type type, object /// /// A YAML type inspector to read fields and properties from a type for serialization. /// -internal sealed class FieldYamlTypeInspector : TypeInspectorSkeleton +internal sealed class FieldYamlTypeInspector : ReflectionTypeInspector { private readonly ITypeResolver _TypeResolver; private readonly INamingConvention _NamingConvention; @@ -399,6 +399,12 @@ public Field(FieldInfo fieldInfo, ITypeResolver typeResolver, INamingConvention public ScalarStyle ScalarStyle { get; set; } + public bool AllowNulls => true; + + public bool Required => false; + + public Type? ConverterType => null; + public void Write(object target, object? value) { throw new NotImplementedException(); @@ -443,6 +449,12 @@ public Property(PropertyInfo propertyInfo, ITypeResolver typeResolver, INamingCo public ScalarStyle ScalarStyle { get; set; } + public bool AllowNulls => true; + + public bool Required => false; + + public Type? ConverterType => null; + public T? GetCustomAttribute() where T : Attribute { return _PropertyInfo.GetCustomAttributes(typeof(T), true).OfType().FirstOrDefault(); @@ -481,22 +493,22 @@ public ResourceNodeDeserializer(INodeDeserializer next) _Factory = new SpecFactory(); } - bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) + bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value, ObjectDeserializer rootDeserializer) { if (typeof(ResourceObject).IsAssignableFrom(expectedType)) { - var comment = reader.Current == null || RunspaceContext.CurrentThread == null ? null : HostHelper.GetCommentMeta(RunspaceContext.CurrentThread.Source?.File, reader.Current.Start.Line - 2, reader.Current.Start.Column); - var resource = MapResource(reader, nestedObjectDeserializer, comment); + var comment = reader.Current == null || RunspaceContext.CurrentThread == null ? null : HostHelper.GetCommentMeta(RunspaceContext.CurrentThread.Source?.File, (int)reader.Current.Start.Line - 2, (int)reader.Current.Start.Column); + var resource = MapResource(reader, nestedObjectDeserializer, comment, rootDeserializer); value = new ResourceObject(resource); return true; } else { - return _Next.Deserialize(reader, expectedType, nestedObjectDeserializer, out value); + return _Next.Deserialize(reader, expectedType, nestedObjectDeserializer, out value, rootDeserializer); } } - private IResource? MapResource(IParser reader, Func nestedObjectDeserializer, CommentMetadata? comment) + private IResource? MapResource(IParser reader, Func nestedObjectDeserializer, CommentMetadata? comment, ObjectDeserializer rootDeserializer) { IResource? result = null; string? apiVersion = null; @@ -504,7 +516,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func(out var mappingStart) && mappingStart != null) { - var extent = new SourceExtent(RunspaceContext.CurrentThread!.Source!.File, mappingStart.Start.Line, mappingStart.Start.Column); + var extent = new SourceExtent(RunspaceContext.CurrentThread!.Source!.File, (int?)mappingStart.Start.Line, (int?)mappingStart.Start.Column); while (reader.TryConsume(out var scalar) && scalar != null) { // Read apiVersion @@ -518,12 +530,12 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out ResourceMetadata? metadata) + private bool TryMetadata(IParser reader, Scalar scalar, Func nestedObjectDeserializer, out ResourceMetadata? metadata, ObjectDeserializer rootDeserializer) { metadata = null; if (scalar.Value != FIELD_METADATA) @@ -568,7 +580,7 @@ private bool TryMetadata(IParser reader, Scalar scalar, Func nestedObjectDeserializer, ResourceMetadata? metadata, CommentMetadata? comment, ISourceExtent extent, out IResource? spec) + private bool TrySpec(IParser reader, Scalar scalar, string apiVersion, string kind, Func nestedObjectDeserializer, ResourceMetadata? metadata, CommentMetadata? comment, ISourceExtent extent, out IResource? spec, ObjectDeserializer rootDeserializer) { spec = null; - return scalar.Value == FIELD_SPEC && TryResource(reader, apiVersion, kind, nestedObjectDeserializer, metadata, comment, extent, out spec); + return scalar.Value == FIELD_SPEC && TryResource(reader, apiVersion, kind, nestedObjectDeserializer, metadata, comment, extent, out spec, rootDeserializer); } - private bool TryResource(IParser reader, string apiVersion, string kind, Func nestedObjectDeserializer, ResourceMetadata? metadata, CommentMetadata? comment, ISourceExtent extent, out IResource? spec) + private bool TryResource(IParser reader, string apiVersion, string kind, Func nestedObjectDeserializer, ResourceMetadata? metadata, CommentMetadata? comment, ISourceExtent extent, out IResource? spec, ObjectDeserializer rootDeserializer) { spec = null; if (_Factory.TryDescriptor(apiVersion, kind, out var descriptor) && reader.Current is MappingStart) { - if (!_Next.Deserialize(reader, descriptor.SpecType, nestedObjectDeserializer, out var value)) + if (!_Next.Deserialize(reader, descriptor.SpecType, nestedObjectDeserializer, out var value, rootDeserializer)) return false; spec = descriptor.CreateInstance(extent.File, metadata, comment, extent, value); @@ -616,7 +628,7 @@ public LanguageExpressionDeserializer(INodeDeserializer next) _FunctionBuilder = new FunctionBuilder(); } - bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) + bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value, ObjectDeserializer rootDeserializer) { if (typeof(LanguageExpression).IsAssignableFrom(expectedType)) { @@ -626,7 +638,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) + bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value, ObjectDeserializer rootDeserializer) { if (expectedType == typeof(PSObject[]) && reader.Current is MappingStart) { var parser = reader as YamlEmitterParser; var fileInfo = parser?.Info ?? _SourceInfo; - var lineNumber = reader.Current.Start.Line; - var linePosition = reader.Current.Start.Column; - value = _Converter.ReadYaml(reader, typeof(PSObject)); + var lineNumber = (int)reader.Current.Start.Line; + var linePosition = (int)reader.Current.Start.Column; + value = _Converter.ReadYaml(reader, typeof(PSObject), rootDeserializer); if (value is PSObject pso) { pso.UseTargetInfo(out var info); @@ -909,7 +921,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value) + bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, out object? value, ObjectDeserializer rootDeserializer) { value = null; if (expectedType == typeof(TargetObject[]) && reader.Current is MappingStart) { - if (TryGetTargetObject(reader, out var targetObject) && targetObject != null) + if (TryGetTargetObject(reader, out var targetObject, rootDeserializer) && targetObject != null) { value = new TargetObject[] { targetObject }; return true; @@ -942,7 +954,7 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func(); while (reader.Current is MappingStart) { - if (TryGetTargetObject(reader, out var targetObject) && targetObject != null) + if (TryGetTargetObject(reader, out var targetObject, rootDeserializer) && targetObject != null) { result.Add(targetObject); } @@ -952,19 +964,19 @@ bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, Func(out var scalar) && !string.IsNullOrEmpty(scalar.Value) ? new InfoString(scalar.Value) : new InfoString(); } - public void WriteYaml(IEmitter emitter, object? value, Type type) + public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { if (value is InfoString info && info.HasValue && info.Text != null) emitter.Emit(new Scalar(info.Text)); diff --git a/src/PSRule/packages.lock.json b/src/PSRule/packages.lock.json index 6db1f4ee8c..e7eb7d2c4c 100644 --- a/src/PSRule/packages.lock.json +++ b/src/PSRule/packages.lock.json @@ -1051,8 +1051,8 @@ }, "YamlDotNet": { "type": "Transitive", - "resolved": "15.3.0", - "contentHash": "F93japYa9YrJ59AZGhgdaUGHN7ITJ55FBBg/D/8C0BDgahv/rQD6MOSwHxOJJpon1kYyslVbeBrQ2wcJhox01w==" + "resolved": "16.1.3", + "contentHash": "gtHGiDvU9VTtWte8f0thIM38cL1oowOjStKpeAEKKfA+Rc4AvekJzqFDZiiPcc4kw00ZiwR4OTJS56L16q98DQ==" }, "Microsoft.PSRule.Badges": { "type": "Project", @@ -1064,7 +1064,7 @@ "type": "Project", "dependencies": { "Newtonsoft.Json": "[13.0.3, )", - "YamlDotNet": "[15.3.0, )" + "YamlDotNet": "[16.1.3, )" } } }