diff options
author | Marek Safar <marek.safar@gmail.com> | 2018-04-02 00:54:57 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2018-04-02 00:54:57 +0300 |
commit | f4951179bb053a9264f063c824720d6237ae55f1 (patch) | |
tree | f7beda10c1e1c9f8a8f4c21a000993598ea0502c /src/System.Private.Xml | |
parent | e89c5c9646d29d74a069f8f9630e35858b6bb076 (diff) | |
parent | 79b3c40e4322fd1778ad075214c90af93e5d2adf (diff) |
Merge remote-tracking branch 'upstream/release/2.1' into 2.1-merge
Diffstat (limited to 'src/System.Private.Xml')
28 files changed, 309 insertions, 70 deletions
diff --git a/src/System.Private.Xml/src/Resources/Strings.resx b/src/System.Private.Xml/src/Resources/Strings.resx index b7c8d8724f..073ceecb21 100644 --- a/src/System.Private.Xml/src/Resources/Strings.resx +++ b/src/System.Private.Xml/src/Resources/Strings.resx @@ -3413,42 +3413,38 @@ building and deploying the assemblies with the application. </data> <data name="HelpUsage" xml:space="preserve"> <value> -Usage: dotnet {0} [[/assembly:<assembly name>] | [<assembly file location>]] - [/type:] [/debug]. - </value> +Usage: dotnet {0} [--assembly <assembly file path>] [--type <type name>]</value> </data> <data name="HelpDevOptions" xml:space="preserve"> - <value> Developer options:</value> + <value> + Developer options:</value> </data> <data name="HelpAssembly" xml:space="preserve"> - <value> {0} Assembly location or display name. Short form is '{1}'.</value> + <value> {0}|{1} Assembly location or display name.</value> </data> <data name="HelpType" xml:space="preserve"> - <value> {0} Generate code for serialization/deserialization of the - specified type from the input assembly. Short form is '{1}'.</value> + <value> {0} Generate code for serialization/deserialization of the specified type from the input assembly.</value> </data> <data name="HelpForce" xml:space="preserve"> - <value> {0} Forces overwrite of a previously generated assembly. - Short form is '{1}'.</value> + <value> {0} Forces overwrite of a previously generated assembly.</value> </data> <data name="HelpProxy" xml:space="preserve"> - <value> {0} Generate serialization code only for proxy classes and web - method parameters. Short form is '{1}'.</value> + <value> {0} Generate serialization code only for proxy classes and web method parameters.</value> </data> <data name="HelpOut" xml:space="preserve"> - <value> {0} Output directory name (default: target assembly location). - Short form is '{1}'.</value> + <value> {0}|{1} Output directory name (default: target assembly location).</value> </data> <data name="HelpMiscOptions" xml:space="preserve"> - <value> Miscellaneous options:</value> + <value> + Miscellaneous options:</value> </data> <data name="HelpHelp" xml:space="preserve"> - <value> {0} or {1} Show this message</value> + <value> {0}|{1} Show help.</value> </data> <data name="MoreHelp" xml:space="preserve"> <value>If you would like more help, please type "sgen {0}".</value> </data> <data name="GenerateSerializerNotFound" xml:space="preserve"> - <value>`System.Xml.Serialization.XmlSerializer` does not have a method named `GenerateSerializerNotFound`. SGen does not support the framework of the version you are using.</value> + <value>Method 'System.Xml.Serialization.XmlSerializer.GenerateSerializer' was not found. This is likely because you are using an older version of the framework. Please update to .NET Core v2.1 or later.</value> </data> -</root>
\ No newline at end of file +</root> diff --git a/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs b/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs index a1e6c3e1d2..3c8f752f65 100644 --- a/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs +++ b/src/System.Private.Xml/src/System/Xml/Core/XmlEncodedRawTextWriter.cs @@ -171,6 +171,11 @@ namespace System.Xml _textContentMarks[0] = 1; _charEntityFallback = new CharEntityEncoderFallback(); + + // grab bom before possibly changing encoding settings + ReadOnlySpan<byte> bom = encoding.Preamble; + + // the encoding instance this creates can differ from the one passed in this.encoding = Encoding.GetEncoding( settings.Encoding.CodePage, _charEntityFallback, @@ -180,7 +185,6 @@ namespace System.Xml if (!stream.CanSeek || stream.Position == 0) { - ReadOnlySpan<byte> bom = encoding.Preamble; if (bom.Length != 0) { this.stream.Write(bom); diff --git a/src/System.Private.Xml/src/System/Xml/NameTable.cs b/src/System.Private.Xml/src/System/Xml/NameTable.cs index 2218a369e8..2317dd9767 100644 --- a/src/System.Private.Xml/src/System/Xml/NameTable.cs +++ b/src/System.Private.Xml/src/System/Xml/NameTable.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Runtime.InteropServices; namespace System.Xml { @@ -197,7 +198,7 @@ namespace System.Xml Entry[] oldEntries = _entries; Entry[] newEntries = new Entry[newMask + 1]; - // use oldEntries.Length to eliminate the range check + // use oldEntries.Length to eliminate the range check for (int i = 0; i < oldEntries.Length; i++) { Entry e = oldEntries[i]; @@ -234,13 +235,13 @@ namespace System.Xml private static int ComputeHash32(string key) { - ReadOnlySpan<byte> bytes = key.AsReadOnlySpan().AsBytes(); + ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(key.AsSpan()); return Marvin.ComputeHash32(bytes, Marvin.DefaultSeed); } private static int ComputeHash32(char[] key, int start, int len) { - ReadOnlySpan<byte> bytes = key.AsReadOnlySpan().Slice(start, len).AsBytes(); + ReadOnlySpan<byte> bytes = MemoryMarshal.AsBytes(key.AsSpan(start, len)); return Marvin.ComputeHash32(bytes, Marvin.DefaultSeed); } } diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/SchemaImporter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/SchemaImporter.cs index 974aa82ba4..8bf4b20188 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/SchemaImporter.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/SchemaImporter.cs @@ -155,7 +155,7 @@ namespace System.Xml.Serialization TypeDesc typeDesc = Scope.GetTypeDesc(typeof(object)); StructMapping mapping = new StructMapping(); mapping.TypeDesc = typeDesc; - mapping.Members = new MemberMapping[0]; + mapping.Members = Array.Empty<MemberMapping>(); mapping.IncludeInSchema = false; mapping.TypeName = Soap.UrType; mapping.Namespace = XmlSchema.Namespace; diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs index 05838f6828..383946e7d4 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/SoapReflectionImporter.cs @@ -266,7 +266,7 @@ namespace System.Xml.Serialization StructMapping mapping = new StructMapping(); mapping.IsSoap = true; mapping.TypeDesc = typeDesc; - mapping.Members = new MemberMapping[0]; + mapping.Members = Array.Empty<MemberMapping>(); mapping.IncludeInSchema = false; mapping.TypeName = Soap.UrType; mapping.Namespace = XmlSchema.Namespace; @@ -739,7 +739,7 @@ namespace System.Xml.Serialization attribute.Mapping = ImportTypeMapping(_modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType), limiter); attribute.Default = GetDefaultValue(model.FieldTypeDesc, a); accessor.Attribute = attribute; - accessor.Elements = new ElementAccessor[0]; + accessor.Elements = Array.Empty<ElementAccessor>(); } else { diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/Types.cs b/src/System.Private.Xml/src/System/Xml/Serialization/Types.cs index 079ec5e661..8f099cc27f 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/Types.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/Types.cs @@ -1253,7 +1253,7 @@ namespace System.Xml.Serialization { if (typeof(IEnumerable).IsAssignableFrom(type)) { - MethodInfo enumerator = type.GetMethod("GetEnumerator", new Type[0]); + MethodInfo enumerator = type.GetMethod("GetEnumerator", Array.Empty<Type>()); if (enumerator == null || !typeof(IEnumerator).IsAssignableFrom(enumerator.ReturnType)) { diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs index 8dd5777b34..6d4dc7c57e 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSchemaImporter.cs @@ -1166,7 +1166,7 @@ namespace System.Xml.Serialization accessor.Mapping = mapping; MemberMapping member = new MemberMapping(); - member.Elements = new ElementAccessor[0]; + member.Elements = Array.Empty<ElementAccessor>(); member.Text = accessor; if (isMixed) { @@ -1499,7 +1499,7 @@ namespace System.Xml.Serialization AttributeAccessor accessor = ImportAttribute(attribute, identifier, ns, attribute); if (accessor == null) return; MemberMapping member = new MemberMapping(); - member.Elements = new ElementAccessor[0]; + member.Elements = Array.Empty<ElementAccessor>(); member.Attribute = accessor; member.Name = CodeIdentifier.MakeValid(Accessor.UnescapeName(accessor.Name)); member.Name = membersScope.AddUnique(member.Name, member); @@ -1529,7 +1529,7 @@ namespace System.Xml.Serialization accessor.Mapping = mapping; MemberMapping member = new MemberMapping(); - member.Elements = new ElementAccessor[0]; + member.Elements = Array.Empty<ElementAccessor>(); member.Attribute = accessor; member.Name = membersScope.MakeRightCase("AnyAttr"); member.Name = membersScope.AddUnique(member.Name, member); @@ -1584,7 +1584,7 @@ namespace System.Xml.Serialization xmlnsMapping.TypeDesc = xmlnsTypeDesc; xmlnsMapping.TypeName = xmlnsMapping.TypeDesc.Name; - xmlnsMapping.Members = new MemberMapping[0]; + xmlnsMapping.Members = Array.Empty<MemberMapping>(); xmlnsMapping.IncludeInSchema = false; xmlnsMapping.ReferencedByTopLevelElement = true; diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs index c9882b4b25..17a11a2cf5 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs @@ -111,7 +111,7 @@ namespace System.Xml.Serialization private string _guidID; private string _timeSpanID; - private static bool s_checkDeserializeAdvances; + private static bool s_checkDeserializeAdvances=false; protected abstract void InitIDs(); @@ -1106,7 +1106,7 @@ namespace System.Xml.Serialization if (arraySize != null && arraySize.Length > 0) dimensions = arraySize.Split(null); else - dimensions = new string[0]; + dimensions = Array.Empty<string>(); soapArrayInfo.dimensions = 0; soapArrayInfo.length = -1; @@ -2411,7 +2411,7 @@ namespace System.Xml.Serialization internal void GenerateEnd() { - GenerateEnd(new string[0], new XmlMapping[0], new Type[0]); + GenerateEnd(Array.Empty<string>(), Array.Empty<XmlMapping>(), Array.Empty<Type>()); } internal void GenerateEnd(string[] methods, XmlMapping[] xmlMappings, Type[] types) { @@ -3573,7 +3573,7 @@ namespace System.Xml.Serialization Writer.Write(", "); WriteQuotedCSharpString(structMapping.Namespace); Writer.WriteLine(");"); - members = new Member[0]; + members = Array.Empty<Member>(); anyFixups = false; fixupMethodName = null; } diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs index 766ee3628a..dda50dfb90 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationWriter.cs @@ -4153,6 +4153,15 @@ namespace System.Xml.Serialization Writer.Write(source); Writer.Write(".Length != 0)"); } + else if(value is Double || value is Single) + { + Writer.Write("!"); + Writer.Write(source); + Writer.Write(".Equals("); + Type type= Type.GetType(mapping.TypeDesc.Type.FullName); + WriteValue(type != null ? Convert.ChangeType(value, type) : value); + Writer.Write(")"); + } else { Writer.Write(source); @@ -4220,9 +4229,17 @@ namespace System.Xml.Serialization Writer.Write(((Int32)value).ToString(null, NumberFormatInfo.InvariantInfo)); else if (type == typeof(Double)) { - if (double.IsNaN((Double)value)) + if (Double.IsNaN((Double)value)) + { + Writer.Write("System.Double.NaN"); + } + else if(Double.IsPositiveInfinity((Double)value)) { - Writer.Write("double.NaN"); + Writer.Write("System.Double.PositiveInfinity"); + } + else if(Double.IsNegativeInfinity((Double)value)) + { + Writer.Write("System.Double.NegativeInfinity"); } else { @@ -4246,6 +4263,14 @@ namespace System.Xml.Serialization { Writer.Write("System.Single.NaN"); } + else if(Single.IsPositiveInfinity((Single)value)) + { + Writer.Write("System.Single.PositiveInfinity"); + } + else if (Single.IsNegativeInfinity((Single)value)) + { + Writer.Write("System.Single.NegativeInfinity"); + } else { Writer.Write(((Single)value).ToString("R", NumberFormatInfo.InvariantInfo)); diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index e7a3342436..25fdb4df57 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -159,6 +159,7 @@ namespace System.Xml.Serialization internal string DefaultNamespace = null; #endif private Type _rootType; + private bool _isReflectionBasedSerializer = false; private static TempAssemblyCache s_cache = new TempAssemblyCache(); private static volatile XmlSerializerNamespaces s_defaultNamespaces; @@ -447,7 +448,7 @@ namespace System.Xml.Serialization } SerializePrimitive(xmlWriter, o, namespaces); } - else if (ShouldUseReflectionBasedSerialization(_mapping)) + else if (ShouldUseReflectionBasedSerialization(_mapping) || _isReflectionBasedSerializer) { SerializeUsingReflection(xmlWriter, o, namespaces, encodingStyle, id); } @@ -587,7 +588,7 @@ namespace System.Xml.Serialization } return DeserializePrimitive(xmlReader, events); } - else if (ShouldUseReflectionBasedSerialization(_mapping)) + else if (ShouldUseReflectionBasedSerialization(_mapping) || _isReflectionBasedSerializer) { return DeserializeUsingReflection(xmlReader, encodingStyle, events); } @@ -797,6 +798,7 @@ namespace System.Xml.Serialization serializers[i] = new XmlSerializer(); serializers[i]._rootType = type; serializers[i]._mapping = mappings[i]; + serializers[i]._isReflectionBasedSerializer = true; } return serializers; diff --git a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializerFactory.cs b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializerFactory.cs index cfd9374aff..95f2f17bf9 100644 --- a/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializerFactory.cs +++ b/src/System.Private.Xml/src/System/Xml/Serialization/XmlSerializerFactory.cs @@ -40,7 +40,7 @@ namespace System.Xml.Serialization /// </devdoc> public XmlSerializer CreateSerializer(Type type, XmlRootAttribute root) { - return CreateSerializer(type, null, new Type[0], root, null, null); + return CreateSerializer(type, null, Array.Empty<Type>(), root, null, null); } /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer3"]/*' /> @@ -58,7 +58,7 @@ namespace System.Xml.Serialization /// </devdoc> public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides) { - return CreateSerializer(type, overrides, new Type[0], null, null, null); + return CreateSerializer(type, overrides, Array.Empty<Type>(), null, null, null); } /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer5"]/*' /> diff --git a/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/DbgCompiler.cs b/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/DbgCompiler.cs index 0dce03c365..aa992b9ecf 100644 --- a/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/DbgCompiler.cs +++ b/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/DbgCompiler.cs @@ -32,7 +32,7 @@ namespace System.Xml.Xsl.XsltOld private DbgData() { _styleSheet = null; - _variables = new VariableAction[0]; + _variables = Array.Empty<VariableAction>(); } public static DbgData Empty { get { return s_nullDbgData; } } } diff --git a/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/UseAttributeSetsAction.cs b/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/UseAttributeSetsAction.cs index bac0d33715..7f1fc34c64 100644 --- a/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/UseAttributeSetsAction.cs +++ b/src/System.Private.Xml/src/System/Xml/Xsl/XsltOld/UseAttributeSetsAction.cs @@ -32,7 +32,7 @@ namespace System.Xml.Xsl.XsltOld if (_useString.Length == 0) { // Split creates empty node is spliting empty string - _useAttributeSets = new XmlQualifiedName[0]; + _useAttributeSets = Array.Empty<XmlQualifiedName>(); return; } @@ -56,7 +56,7 @@ namespace System.Xml.Xsl.XsltOld throw; } // Ignore the whole list in forwards-compatible mode - _useAttributeSets = new XmlQualifiedName[0]; + _useAttributeSets = Array.Empty<XmlQualifiedName>(); } } diff --git a/src/System.Private.Xml/tests/Misc/System.Xml.Misc.Tests.csproj b/src/System.Private.Xml/tests/Misc/System.Xml.Misc.Tests.csproj index 275891669f..102aa3cc79 100644 --- a/src/System.Private.Xml/tests/Misc/System.Xml.Misc.Tests.csproj +++ b/src/System.Private.Xml/tests/Misc/System.Xml.Misc.Tests.csproj @@ -10,6 +10,7 @@ <ItemGroup> <Compile Include="RandomizedHashing.cs" /> <Compile Include="..\..\src\System\Xml\Core\SecureStringHasher.cs" /> + <Compile Include="XmlUrlResolverTests.cs" /> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> </Project>
\ No newline at end of file diff --git a/src/System.Private.Xml/tests/Misc/XmlUrlResolverTests.cs b/src/System.Private.Xml/tests/Misc/XmlUrlResolverTests.cs new file mode 100644 index 0000000000..ae7f394cee --- /dev/null +++ b/src/System.Private.Xml/tests/Misc/XmlUrlResolverTests.cs @@ -0,0 +1,77 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using Xunit; + +namespace System.Xml.Tests +{ + public class XmlUriResolverTests + { + [Fact] + public void Resolving_RelativeBase_Throws() + { + var resolver = new XmlUrlResolver(); + Assert.Throws<NotSupportedException>(() => resolver.ResolveUri( + new Uri(Environment.CurrentDirectory + Path.DirectorySeparatorChar, UriKind.Relative), "test.xml")); + } + + [Theory] + [MemberData(nameof(GetBaseUriAndPath))] + public void Resolving_LocalPath_Ok(Uri baseUri, string path) + { + var resolver = new XmlUrlResolver(); + Uri resolvedUri = resolver.ResolveUri(baseUri, path); + + Assert.Equal(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, path)), resolvedUri.LocalPath); + Assert.True(resolvedUri.LocalPath.EndsWith(path.Replace('/', Path.DirectorySeparatorChar))); + } + + [Theory] + [MemberData(nameof(XmlFileTargets))] + public void Resolving_OnlyWithBaseUri_Ok(string basePath) + { + var baseUri = new Uri(Path.GetFullPath(basePath)); + var resolver = new XmlUrlResolver(); + Uri resolvedUri = resolver.ResolveUri(baseUri, string.Empty); + + Assert.Equal(Path.GetFullPath(basePath), resolvedUri.LocalPath); + } + + public static IEnumerable<object[]> GetBaseUriAndPath() + { + // Base URI as null is the default for internal Xml operation. + var baseUris = new List<Uri> { null }; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // The case below does not work on Unix, the '#' ends up treated as a fragment and the path is cut there. + var currDirWithDirSeparator = Environment.CurrentDirectory + Path.DirectorySeparatorChar; + baseUris.Add(new Uri(currDirWithDirSeparator, UriKind.Absolute)); + baseUris.Add(new Uri(string.Empty, UriKind.RelativeOrAbsolute)); + } + + foreach (Uri baseUri in baseUris) + { + foreach (object[] targetFile in XmlFileTargets) + yield return new object[] { baseUri, targetFile[0] }; + } + } + + public static IEnumerable<object[]> XmlFileTargets => new object[][] + { + new object[] { "f#/t/\u00eb/test.xml" }, + new object[] { "/f#/t/\u00eb/t#st.xml" }, + new object[] { "/f#/\u00e3/\u00eb/t\u00ebst.xml" }, + new object[] { "u/t/c/test.xml" }, + new object[] { "u/t/c/t#st.xml" }, + new object[] { "/u/t/c/t\u00ebst.xml" }, + new object[] { "test.xml" }, + new object[] { "t#st.xml" }, + new object[] { "t\u00ebst.xml" } + }; + } +} diff --git a/src/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs b/src/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs index afb534ae18..82a09864ec 100644 --- a/src/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs +++ b/src/System.Private.Xml/tests/Writers/XmlWriterApi/TCFullEndElement.cs @@ -4251,7 +4251,6 @@ namespace System.Xml.Tests [XmlWriterInlineData(2, "XmlQualifiedName", "XmlQualifiedName", true, null )] public void writeValue_27(XmlWriterUtils utils, int param, string sourceStr, string destStr, bool isValid, object expVal) { - Type source = typeMapper[sourceStr]; Type dest = typeMapper[destStr]; CultureInfo origCulture = null; @@ -4270,7 +4269,8 @@ namespace System.Xml.Tests if (param == 1) w.WriteValue(value[sourceStr]); else - w.WriteAttributeString("a", value[sourceStr].ToString()); + w.WriteAttributeString("a", + string.Format(CultureInfo.InvariantCulture, "{0}", value[sourceStr])); w.WriteEndElement(); } try diff --git a/src/System.Private.Xml/tests/XmlReader/XmlResolver/XmlSystemPathResolverTests.cs b/src/System.Private.Xml/tests/XmlReader/XmlResolver/XmlSystemPathResolverTests.cs index 4404f5fb9c..8c711bae7c 100644 --- a/src/System.Private.Xml/tests/XmlReader/XmlResolver/XmlSystemPathResolverTests.cs +++ b/src/System.Private.Xml/tests/XmlReader/XmlResolver/XmlSystemPathResolverTests.cs @@ -76,6 +76,7 @@ namespace System.Xml.Tests || e is FileNotFoundException || e is FormatException || e is UnauthorizedAccessException + || e is IOException || e is XmlException); } diff --git a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Reprocess.cs b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Reprocess.cs index 0acd938c88..269dffa070 100644 --- a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Reprocess.cs +++ b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Reprocess.cs @@ -635,15 +635,15 @@ namespace System.Xml.Tests string correctUri = Path.GetFullPath(path); _output.WriteLine("Include uri: " + includeUri); _output.WriteLine("Correct uri: " + correctUri); - Stream s = new FileStream(Path.GetFullPath(path), FileMode.Open, FileAccess.Read, FileShare.Read, 1); - XmlReader r = XmlReader.Create(s, new XmlReaderSettings(), includeUri); - _output.WriteLine("Reader uri: " + r.BaseURI); - XmlSchema som = null; - using (r) + using (Stream s = new FileStream(Path.GetFullPath(path), FileMode.Open, FileAccess.Read, FileShare.Read, 1)) { - som = XmlSchema.Read(r, new ValidationEventHandler(ValidationCallback)); + XmlReader r = XmlReader.Create(s, new XmlReaderSettings(), includeUri); + _output.WriteLine("Reader uri: " + r.BaseURI); + using (r) + { + return XmlSchema.Read(r, new ValidationEventHandler(ValidationCallback)); + } } - return som; } } } diff --git a/src/System.Private.Xml/tests/XmlSerializer/Performance/System.Xml.XmlSerializer.Performance.Tests.csproj b/src/System.Private.Xml/tests/XmlSerializer/Performance/System.Xml.XmlSerializer.Performance.Tests.csproj index a04c4db3fb..a36a097ac3 100644 --- a/src/System.Private.Xml/tests/XmlSerializer/Performance/System.Xml.XmlSerializer.Performance.Tests.csproj +++ b/src/System.Private.Xml/tests/XmlSerializer/Performance/System.Xml.XmlSerializer.Performance.Tests.csproj @@ -11,7 +11,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" /> <ItemGroup> - <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\Utils.cs" /> + <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Utils.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.RuntimeOnly.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\Performance\PerformanceTestsCommon.cs" /> @@ -24,4 +24,4 @@ </ProjectReference> </ItemGroup> <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> -</Project>
\ No newline at end of file +</Project> diff --git a/src/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj b/src/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj index 11e1057ae5..ba3f95079b 100644 --- a/src/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj +++ b/src/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj @@ -11,7 +11,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Release|AnyCPU'" /> <ItemGroup> - <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\Utils.cs" /> + <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Utils.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.RuntimeOnly.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\..\System.Runtime.Serialization.Xml\tests\Performance\PerformanceTestsCommon.cs" /> diff --git a/src/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj b/src/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj index 261a6360d6..f1bfe4c675 100644 --- a/src/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj +++ b/src/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj @@ -11,7 +11,7 @@ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Debug|AnyCPU'" /> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Release|AnyCPU'" /> <ItemGroup> - <Compile Include="$(TestSourceFolder)..\..\..\System.Runtime.Serialization.Xml\tests\Utils.cs" /> + <Compile Include="$(CommonTestPath)\System\Runtime\Serialization\Utils.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.RuntimeOnly.cs" /> <Compile Include="$(TestSourceFolder)..\..\..\System.Runtime.Serialization.Xml\tests\SerializationTypes.cs" /> <Compile Include="$(TestSourceFolder)XmlSerializerTests.cs" /> diff --git a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs index 10281561d3..81c8f7bb1e 100644 --- a/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs +++ b/src/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs @@ -477,15 +477,15 @@ string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> public static void XML_TypeWithXmlSchemaFormAttribute() { var value = new TypeWithXmlSchemaFormAttribute() { NoneSchemaFormListProperty = new List<string> { "abc" }, QualifiedSchemaFormListProperty = new List<bool> { true }, UnqualifiedSchemaFormListProperty = new List<int> { 1 } }; - var acutal = SerializeAndDeserialize<TypeWithXmlSchemaFormAttribute>(value, + var actual = SerializeAndDeserialize<TypeWithXmlSchemaFormAttribute>(value, @"<?xml version=""1.0""?><TypeWithXmlSchemaFormAttribute xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><UnqualifiedSchemaFormListProperty><int>1</int></UnqualifiedSchemaFormListProperty><NoneSchemaFormListProperty><NoneParameter>abc</NoneParameter></NoneSchemaFormListProperty><QualifiedSchemaFormListProperty><QualifiedParameter>true</QualifiedParameter></QualifiedSchemaFormListProperty></TypeWithXmlSchemaFormAttribute>"); - Assert.StrictEqual(value.NoneSchemaFormListProperty.Count, acutal.NoneSchemaFormListProperty.Count); - Assert.StrictEqual(value.NoneSchemaFormListProperty[0], acutal.NoneSchemaFormListProperty[0]); - Assert.StrictEqual(value.UnqualifiedSchemaFormListProperty.Count, acutal.UnqualifiedSchemaFormListProperty.Count); - Assert.StrictEqual(value.UnqualifiedSchemaFormListProperty[0], acutal.UnqualifiedSchemaFormListProperty[0]); - Assert.StrictEqual(value.QualifiedSchemaFormListProperty.Count, acutal.QualifiedSchemaFormListProperty.Count); - Assert.StrictEqual(value.QualifiedSchemaFormListProperty[0], acutal.QualifiedSchemaFormListProperty[0]); + Assert.StrictEqual(value.NoneSchemaFormListProperty.Count, actual.NoneSchemaFormListProperty.Count); + Assert.StrictEqual(value.NoneSchemaFormListProperty[0], actual.NoneSchemaFormListProperty[0]); + Assert.StrictEqual(value.UnqualifiedSchemaFormListProperty.Count, actual.UnqualifiedSchemaFormListProperty.Count); + Assert.StrictEqual(value.UnqualifiedSchemaFormListProperty[0], actual.UnqualifiedSchemaFormListProperty[0]); + Assert.StrictEqual(value.QualifiedSchemaFormListProperty.Count, actual.QualifiedSchemaFormListProperty.Count); + Assert.StrictEqual(value.QualifiedSchemaFormListProperty[0], actual.QualifiedSchemaFormListProperty[0]); } [Fact] @@ -1614,6 +1614,97 @@ string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> } [Fact] + public static void Xml_DefaultValueAttributeSetToPositiveInfinityTest() + { + var value = new DefaultValuesSetToPositiveInfinity(); + var actual = SerializeAndDeserialize(value, +@"<?xml version=""1.0""?> +<DefaultValuesSetToPositiveInfinity xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> + <DoubleField>0</DoubleField> + <SingleField>0</SingleField> + <DoubleProp>0</DoubleProp> + <FloatProp>0</FloatProp> +</DefaultValuesSetToPositiveInfinity>"); + Assert.NotNull(actual); + Assert.Equal(value, actual); + } + + [Fact] + public static void Xml_DefaultValueAttributeSetToNegativeInfinityTest() + { + var value = new DefaultValuesSetToNegativeInfinity(); + var actual = SerializeAndDeserialize(value, +@"<?xml version=""1.0""?> +<DefaultValuesSetToNegativeInfinity xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> + <DoubleField>0</DoubleField> + <SingleField>0</SingleField> + <DoubleProp>0</DoubleProp> + <FloatProp>0</FloatProp> +</DefaultValuesSetToNegativeInfinity>"); + Assert.NotNull(actual); + Assert.Equal(value, actual); + } + + [ActiveIssue(28321)] + [Fact] + public static void SerializeWithDefaultValueSetToNaNTest() + { + var value = new DefaultValuesSetToNaN(); + value.DoubleField = Double.NaN; + value.SingleField = Single.NaN; + value.FloatProp = Single.NaN; + value.DoubleProp = Double.NaN; + + bool result=SerializeWithDefaultValue(value, +@"<?xml version=""1.0""?> +<DefaultValuesSetToNaN xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />"); + Assert.True(result); + } + + [Fact] + public static void SerializeWithDefaultValueSetToPositiveInfinityTest() + { + var value = new DefaultValuesSetToPositiveInfinity(); + value.DoubleField = Double.PositiveInfinity; + value.SingleField = Single.PositiveInfinity; + value.FloatProp = Single.PositiveInfinity; + value.DoubleProp = Double.PositiveInfinity; + + bool result = SerializeWithDefaultValue(value, +@"<?xml version=""1.0""?> +<DefaultValuesSetToPositiveInfinity xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />"); + Assert.True(result); + } + + [Fact] + public static void SerializeWithDefaultValueSetToNegativeInfinityTest() + { + var value = new DefaultValuesSetToNegativeInfinity(); + value.DoubleField = Double.NegativeInfinity; + value.SingleField = Single.NegativeInfinity; + value.FloatProp = Single.NegativeInfinity; + value.DoubleProp = Double.NegativeInfinity; + + bool result = SerializeWithDefaultValue(value, + @"<?xml version=""1.0""?> +<DefaultValuesSetToNegativeInfinity xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" />"); + Assert.True(result); + } + + private static bool SerializeWithDefaultValue<T>(T value, string baseline) + { + XmlSerializer serializer = new XmlSerializer(typeof(T)); + using (MemoryStream ms = new MemoryStream()) + { + serializer.Serialize(ms, value); + ms.Position = 0; + string output = new StreamReader(ms).ReadToEnd(); + Utils.CompareResult result = Utils.Compare(baseline, output); + return result.Equal; + } + } + + [Fact] public static void Xml_TypeWithMismatchBetweenAttributeAndPropertyType() { var value = new TypeWithMismatchBetweenAttributeAndPropertyType(); diff --git a/src/System.Private.Xml/tests/XmlWriter/WriteWithEncoding.cs b/src/System.Private.Xml/tests/XmlWriter/WriteWithEncoding.cs index 78c191a4d8..b764701630 100644 --- a/src/System.Private.Xml/tests/XmlWriter/WriteWithEncoding.cs +++ b/src/System.Private.Xml/tests/XmlWriter/WriteWithEncoding.cs @@ -3,7 +3,9 @@ // See the LICENSE file in the project root for more information. using System.IO; +using System.Linq; using System.Text; +using System.Xml.Xsl; using Xunit; namespace System.Xml.Tests @@ -36,5 +38,38 @@ namespace System.Xml.Tests Assert.Equal("<orderID>1-456-ab١</orderID><orderID>2-36-00a𐀀𐐁</orderID>", s); } + + [Fact] + public void WriteWithUtf32EncodingNoBom() + { + //Given, encoding set to UTF32 with no BOM + var settings = new XmlWriterSettings + { + OmitXmlDeclaration = false, + ConformanceLevel = ConformanceLevel.Document, + Encoding = new UTF32Encoding(false, false, true) + }; + + string resultString; + using (var result = new MemoryStream()) + { + // BOM can be written in this call + var writer = XmlWriter.Create(result, settings); + + // When, do work and get result + writer.WriteStartDocument(); + writer.WriteStartElement("orders"); + writer.WriteElementString("orderID", "1-456-ab\u0661"); + writer.WriteElementString("orderID", "2-36-00a\uD800\uDC00\uD801\uDC01"); + writer.WriteEndElement(); + writer.WriteEndDocument(); + writer.Flush(); + result.Position = 0; + resultString = settings.Encoding.GetString(result.ToArray()); + } + + // Then, last '>' will be cut off in resulting string if BOM is present + Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-32\"?>", string.Concat(resultString.Take(39))); + } } } diff --git a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XslCompiledTransform.cs b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XslCompiledTransform.cs index f9f00e7d3f..0c6dfaf71d 100644 --- a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XslCompiledTransform.cs +++ b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XslCompiledTransform.cs @@ -1616,7 +1616,7 @@ namespace System.Xml.Tests { try { - LoadXSL("\\\\", XslInputType.URI, readerType, new XmlUrlResolver()); + LoadXSL(" ", XslInputType.URI, readerType, new XmlUrlResolver()); } catch (System.ArgumentException) { @@ -2913,7 +2913,7 @@ namespace System.Xml.Tests if (LoadXSL("showParam.xsl", xslInputType, readerType) == 1) { - Assert.Throws<System.ArgumentException>(() => xslt.Transform(szFullFilename, "\\\\")); + Assert.Throws<System.ArgumentException>(() => xslt.Transform(szFullFilename, " ")); return; } diff --git a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltApiV2.cs b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltApiV2.cs index 5e058dce06..e06d0a74e2 100644 --- a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltApiV2.cs +++ b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltApiV2.cs @@ -44,7 +44,7 @@ namespace System.Xml.Tests public String szDefaultNS = "urn:my-object"; public String szEmpty = ""; - public String szInvalid = "*?%(){}[]&!@#$"; + public String szInvalid = "*?%(){}\0[]&!@#$"; public String szLongString = "ThisIsAVeryLongStringToBeStoredAsAVariableToDetermineHowLargeThisBufferForAVariableNameCanBeAndStillFunctionAsExpected"; public String szLongNS = "http://www.microsoft.com/this/is/a/very/long/namespace/uri/to/do/the/api/testing/for/xslt/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/"; public String[] szWhiteSpace = { " ", "\n", "\t", "\r", "\t\n \r\t" }; diff --git a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltSettings.cs b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltSettings.cs index 01d7d5519a..7bfb96f3cc 100644 --- a/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltSettings.cs +++ b/src/System.Private.Xml/tests/Xslt/XslCompiledTransformApi/XsltSettings.cs @@ -5,6 +5,7 @@ using Xunit; using Xunit.Abstractions; using System.IO; +using System.Text.RegularExpressions; using System.Xml.XPath; using System.Xml.Xsl; @@ -335,7 +336,12 @@ namespace System.Xml.Tests StringWriter sw; var e = Assert.ThrowsAny<XsltException>(() => sw = Transform()); - Assert.Contains("Execution of the 'document()' function was prohibited. Use the XsltSettings.EnableDocumentFunction property to enable it.", e.Message); + + // \p{Pi} any kind of opening quote https://www.compart.com/en/unicode/category/Pi + // \p{Pf} any kind of closing quote https://www.compart.com/en/unicode/category/Pf + // \p{Po} any kind of punctuation character that is not a dash, bracket, quote or connector https://www.compart.com/en/unicode/category/Po + Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape("document()") + @"[\p{Pf}\p{Po}]", e.Message); + Assert.Matches(@"\b" + Regex.Escape("XsltSettings.EnableDocumentFunction") + @"\b", e.Message); } } -}
\ No newline at end of file +} diff --git a/src/System.Private.Xml/tests/Xslt/XslTransformApi/CXslTransform.cs b/src/System.Private.Xml/tests/Xslt/XslTransformApi/CXslTransform.cs index 0a8ecb612c..bf9194ae81 100644 --- a/src/System.Private.Xml/tests/Xslt/XslTransformApi/CXslTransform.cs +++ b/src/System.Private.Xml/tests/Xslt/XslTransformApi/CXslTransform.cs @@ -1413,7 +1413,7 @@ namespace System.Xml.Tests { try { - LoadXSL("\\\\", InputType.URI, readerType); + LoadXSL(" ", InputType.URI, readerType); } catch (System.ArgumentException) { @@ -2522,7 +2522,7 @@ namespace System.Xml.Tests if (LoadXSL("showParam.xsl", inputType, readerType) == 1) { - Assert.Throws<System.ArgumentException>(() => xslt.Transform(szFullFilename, "\\\\")); + Assert.Throws<System.ArgumentException>(() => xslt.Transform(szFullFilename, " ")); return; } diff --git a/src/System.Private.Xml/tests/Xslt/XslTransformApi/XSLTransform.cs b/src/System.Private.Xml/tests/Xslt/XslTransformApi/XSLTransform.cs index a75f8ea73c..010efa92a2 100644 --- a/src/System.Private.Xml/tests/Xslt/XslTransformApi/XSLTransform.cs +++ b/src/System.Private.Xml/tests/Xslt/XslTransformApi/XSLTransform.cs @@ -57,7 +57,7 @@ namespace System.Xml.Tests public String szDefaultNS = "urn:my-object"; public String szEmpty = ""; - public String szInvalid = "*?%(){}[]&!@#$"; + public String szInvalid = "*?%()\0{}[]&!@#$"; public String szLongString = "ThisIsAVeryLongStringToBeStoredAsAVariableToDetermineHowLargeThisBufferForAVariableNameCanBeAndStillFunctionAsExpected"; public String szLongNS = "http://www.miocrosoft.com/this/is/a/very/long/namespace/uri/to/do/the/api/testing/for/xslt/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/"; public String[] szWhiteSpace = { " ", "\n", "\t", "\r", "\t\n \r\t" }; |