diff --git a/aas_core_codegen/csharp/lib/_generate_xml_rpc.py b/aas_core_codegen/csharp/lib/_generate_xml_rpc.py index ea5e0d43a..8f5b380b4 100644 --- a/aas_core_codegen/csharp/lib/_generate_xml_rpc.py +++ b/aas_core_codegen/csharp/lib/_generate_xml_rpc.py @@ -78,6 +78,17 @@ def generate(namespace: csharp_common.NamespaceIdentifier) -> str: {{ {I}error = null; +{I}// NOTE (mristin): +{I}// XmlReader.ReadContentAsString throws an InvalidOperationException if +{I}// it starts at an element, so we report a nested element beforehand. +{I}if (reader.NodeType == Xml.XmlNodeType.Element) +{I}{{ +{II}error = new Reporting.Error( +{III}"Expected \\"0\\" or \\"1\\" as the text of a element, " + +{III}$"but got a nested element {{reader.Name}}"); +{II}return null; +{I}}} + {I}string text; {I}try {I}{{ @@ -126,6 +137,17 @@ def generate(namespace: csharp_common.NamespaceIdentifier) -> str: {{ {I}error = null; +{I}// NOTE (mristin): +{I}// XmlReader.ReadContentAsString throws an InvalidOperationException if +{I}// it starts at an element, so we report a nested element beforehand. +{I}if (reader.NodeType == Xml.XmlNodeType.Element) +{I}{{ +{II}error = new Reporting.Error( +{III}"Expected a number as the text of a element, " + +{III}$"but got a nested element {{reader.Name}}"); +{II}return null; +{I}}} + {I}double result; {I}try {I}{{ @@ -172,6 +194,17 @@ def generate(namespace: csharp_common.NamespaceIdentifier) -> str: {{ {I}error = null; +{I}// NOTE (mristin): +{I}// XmlReader.ReadContentAsString throws an InvalidOperationException if +{I}// it starts at an element, so we report a nested element beforehand. +{I}if (reader.NodeType == Xml.XmlNodeType.Element) +{I}{{ +{II}error = new Reporting.Error( +{III}"Expected text as the content of a element, " + +{III}$"but got a nested element {{reader.Name}}"); +{II}return null; +{I}}} + {I}try {I}{{ {II}return reader.ReadContentAsString(); @@ -506,14 +539,16 @@ def generate(namespace: csharp_common.NamespaceIdentifier) -> str: {I}}} {I}else {I}{{ -{II}key = DeserializeStringTextFrom(reader, out error) -{III}?? throw new System.InvalidOperationException( -{IIII}"Unexpected key null when error null"); +{II}string? maybeKey = DeserializeStringTextFrom(reader, out error); {II}if (error != null) {II}{{ {III}return null; {II}}} +{II}key = maybeKey +{III}?? throw new System.InvalidOperationException( +{IIII}"Unexpected key null when error null"); + {II}XmlCommon.ConsumeEndElementInNoNamespace( {III}reader, "name", false, out error); {II}if (error != null) diff --git a/aas_core_codegen/csharp/lib/_generate_xmlization.py b/aas_core_codegen/csharp/lib/_generate_xmlization.py index a6552821b..c8b6d3828 100644 --- a/aas_core_codegen/csharp/lib/_generate_xmlization.py +++ b/aas_core_codegen/csharp/lib/_generate_xmlization.py @@ -402,6 +402,19 @@ def _generate_as_text_combinators( {III}return default!; {II}}} +{II}// NOTE (mristin): +{II}// XmlReader.ReadContentAs* throws an InvalidOperationException if it +{II}// starts at an element, so we have to report a nested element before +{II}// the conversion. A nested element after a text is not our concern +{II}// here, as the caller expects the end element afterwards. +{II}if (reader.NodeType == Xml.XmlNodeType.Element) +{II}{{ +{III}error = new Reporting.Error( +{IIII}$"Expected an XML content representing {{typeof(T).Name}}, " + +{IIII}$"but got a nested element {{reader.Name}}"); +{III}return default!; +{II}}} + {II}try {II}{{ {III}return readContent(reader); diff --git a/aas_core_codegen/csharp/tests/_generate_test_xml_rpc.py b/aas_core_codegen/csharp/tests/_generate_test_xml_rpc.py index 18a1b42ee..6ba2e6a67 100644 --- a/aas_core_codegen/csharp/tests/_generate_test_xml_rpc.py +++ b/aas_core_codegen/csharp/tests/_generate_test_xml_rpc.py @@ -339,6 +339,35 @@ def generate(namespace: csharp_common.NamespaceIdentifier) -> str: Stripped( f"""\ [Test] +public void Test_deserialize_rejects_a_nested_element_in_a_text() +{{ +{I}string[] texts = +{I}{{ +{II}"", +{II}"", +{II}"", +{II}"" +{III}+ "" +{III}+ "something" +{II}+ "" +{I}}}; + +{I}foreach (string text in texts) +{I}{{ +{II}Nodes.JsonNode? result = DeserializeFromString( +{III}text, out Our.Reporting.Error? error); + +{II}Assert.IsNull(result, text); +{II}Assert.IsNotNull(error, text); +{II}Assert.IsTrue( +{III}error!.Cause.Contains("but got a nested element nested"), +{III}$"Unexpected cause for {{text}}: {{error.Cause}}"); +{I}}} +}}""" + ), + Stripped( + f"""\ +[Test] public void Test_deserialize_rejects_repeated_member_key() {{ {I}string text = ( diff --git a/dev/test_data/live_tests/common_test_data/primitive_types/Xml/Unexpected/Unserializable/TypeViolation/something/some_string_as_nested_element.xml b/dev/test_data/live_tests/common_test_data/primitive_types/Xml/Unexpected/Unserializable/TypeViolation/something/some_string_as_nested_element.xml new file mode 100644 index 000000000..176e3bba0 --- /dev/null +++ b/dev/test_data/live_tests/common_test_data/primitive_types/Xml/Unexpected/Unserializable/TypeViolation/something/some_string_as_nested_element.xml @@ -0,0 +1 @@ +true123434.23hello worldSGVsbG8gV29ybGQ= \ No newline at end of file diff --git a/dev/test_data/main/csharp/expected/aas_core_meta.v3/expected_output/AasCore.Aas3_0/xmlization.cs b/dev/test_data/main/csharp/expected/aas_core_meta.v3/expected_output/AasCore.Aas3_0/xmlization.cs index d755359d6..ea857790a 100644 --- a/dev/test_data/main/csharp/expected/aas_core_meta.v3/expected_output/AasCore.Aas3_0/xmlization.cs +++ b/dev/test_data/main/csharp/expected/aas_core_meta.v3/expected_output/AasCore.Aas3_0/xmlization.cs @@ -145,6 +145,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/annotated_assignments/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/annotated_assignments/expected_output/dummy/xmlization.cs index 63ad77716..bb973ac49 100644 --- a/dev/test_data/main/csharp/expected/annotated_assignments/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/annotated_assignments/expected_output/dummy/xmlization.cs @@ -145,6 +145,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/arithmetic/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/arithmetic/expected_output/dummy/xmlization.cs index 3978d092f..d957d6a70 100644 --- a/dev/test_data/main/csharp/expected/arithmetic/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/arithmetic/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/assert_statements/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/assert_statements/expected_output/dummy/xmlization.cs index b878f287b..219c10a67 100644 --- a/dev/test_data/main/csharp/expected/assert_statements/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/assert_statements/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/assignment_targets/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/assignment_targets/expected_output/dummy/xmlization.cs index 443ba38bb..718164678 100644 --- a/dev/test_data/main/csharp/expected/assignment_targets/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/assignment_targets/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/collections_in_returns/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/collections_in_returns/expected_output/dummy/xmlization.cs index cd12bc82f..690def7bd 100644 --- a/dev/test_data/main/csharp/expected/collections_in_returns/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/collections_in_returns/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/constrained_primitives/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/constrained_primitives/expected_output/dummy/xmlization.cs index 608026905..6f563739f 100644 --- a/dev/test_data/main/csharp/expected/constrained_primitives/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/constrained_primitives/expected_output/dummy/xmlization.cs @@ -145,6 +145,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/custom_serialization_names/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/custom_serialization_names/expected_output/dummy/xmlization.cs index 3ed08f82b..17e30abb2 100644 --- a/dev/test_data/main/csharp/expected/custom_serialization_names/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/custom_serialization_names/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/deep_class_hierarchy/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/deep_class_hierarchy/expected_output/dummy/xmlization.cs index 4edf899cb..81a6f7c74 100644 --- a/dev/test_data/main/csharp/expected/deep_class_hierarchy/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/deep_class_hierarchy/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/enum/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/enum/expected_output/dummy/xmlization.cs index 39a173fc0..425ff5baf 100644 --- a/dev/test_data/main/csharp/expected/enum/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/enum/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/float_only/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/float_only/expected_output/dummy/xmlization.cs index 0d473a5ae..2ca99cd61 100644 --- a/dev/test_data/main/csharp/expected/float_only/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/float_only/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/for_statements/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/for_statements/expected_output/dummy/xmlization.cs index a01ed7598..d9438840f 100644 --- a/dev/test_data/main/csharp/expected/for_statements/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/for_statements/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/if_statements/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/if_statements/expected_output/dummy/xmlization.cs index 64260691f..15124b515 100644 --- a/dev/test_data/main/csharp/expected/if_statements/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/if_statements/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/implementation_specific/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/implementation_specific/expected_output/dummy/xmlization.cs index f1c5525b9..ba25c8758 100644 --- a/dev/test_data/main/csharp/expected/implementation_specific/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/implementation_specific/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/int_length_interplay/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/int_length_interplay/expected_output/dummy/xmlization.cs index 9eba82852..7e3aeb47c 100644 --- a/dev/test_data/main/csharp/expected/int_length_interplay/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/int_length_interplay/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/int_parsing_and_lstrip/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/int_parsing_and_lstrip/expected_output/dummy/xmlization.cs index 96a9150e3..54287cf86 100644 --- a/dev/test_data/main/csharp/expected/int_parsing_and_lstrip/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/int_parsing_and_lstrip/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/is_instance/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/is_instance/expected_output/dummy/xmlization.cs index c653682bf..5abeabc91 100644 --- a/dev/test_data/main/csharp/expected/is_instance/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/is_instance/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/json_types/expected_output/dummy.Tests/TestXmlRpc.cs b/dev/test_data/main/csharp/expected/json_types/expected_output/dummy.Tests/TestXmlRpc.cs index 8b64d4c33..f368e3e64 100644 --- a/dev/test_data/main/csharp/expected/json_types/expected_output/dummy.Tests/TestXmlRpc.cs +++ b/dev/test_data/main/csharp/expected/json_types/expected_output/dummy.Tests/TestXmlRpc.cs @@ -285,6 +285,33 @@ public void Test_deserialize_rejects_non_strict_boolean_lexical_form() $"Unexpected cause: {error.Cause}"); } + [Test] + public void Test_deserialize_rejects_a_nested_element_in_a_text() + { + string[] texts = + { + "", + "", + "", + "" + + "" + + "something" + + "" + }; + + foreach (string text in texts) + { + Nodes.JsonNode? result = DeserializeFromString( + text, out Our.Reporting.Error? error); + + Assert.IsNull(result, text); + Assert.IsNotNull(error, text); + Assert.IsTrue( + error!.Cause.Contains("but got a nested element nested"), + $"Unexpected cause for {text}: {error.Cause}"); + } + } + [Test] public void Test_deserialize_rejects_repeated_member_key() { diff --git a/dev/test_data/main/csharp/expected/json_types/expected_output/dummy/xmlrpc.cs b/dev/test_data/main/csharp/expected/json_types/expected_output/dummy/xmlrpc.cs index 609fc4a50..bbf004467 100644 --- a/dev/test_data/main/csharp/expected/json_types/expected_output/dummy/xmlrpc.cs +++ b/dev/test_data/main/csharp/expected/json_types/expected_output/dummy/xmlrpc.cs @@ -38,6 +38,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected \"0\" or \"1\" as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + string text; try { @@ -84,6 +95,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected a number as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + double result; try { @@ -128,6 +150,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected text as the content of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + try { return reader.ReadContentAsString(); @@ -454,14 +487,16 @@ public static class XmlRpc } else { - key = DeserializeStringTextFrom(reader, out error) - ?? throw new System.InvalidOperationException( - "Unexpected key null when error null"); + string? maybeKey = DeserializeStringTextFrom(reader, out error); if (error != null) { return null; } + key = maybeKey + ?? throw new System.InvalidOperationException( + "Unexpected key null when error null"); + XmlCommon.ConsumeEndElementInNoNamespace( reader, "name", false, out error); if (error != null) diff --git a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy.Tests/TestXmlRpc.cs b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy.Tests/TestXmlRpc.cs index 8b64d4c33..f368e3e64 100644 --- a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy.Tests/TestXmlRpc.cs +++ b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy.Tests/TestXmlRpc.cs @@ -285,6 +285,33 @@ public void Test_deserialize_rejects_non_strict_boolean_lexical_form() $"Unexpected cause: {error.Cause}"); } + [Test] + public void Test_deserialize_rejects_a_nested_element_in_a_text() + { + string[] texts = + { + "", + "", + "", + "" + + "" + + "something" + + "" + }; + + foreach (string text in texts) + { + Nodes.JsonNode? result = DeserializeFromString( + text, out Our.Reporting.Error? error); + + Assert.IsNull(result, text); + Assert.IsNotNull(error, text); + Assert.IsTrue( + error!.Cause.Contains("but got a nested element nested"), + $"Unexpected cause for {text}: {error.Cause}"); + } + } + [Test] public void Test_deserialize_rejects_repeated_member_key() { diff --git a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlization.cs index c428a0323..c022254a7 100644 --- a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlization.cs @@ -122,6 +122,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlrpc.cs b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlrpc.cs index 609fc4a50..bbf004467 100644 --- a/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlrpc.cs +++ b/dev/test_data/main/csharp/expected/json_types_in_collections/expected_output/dummy/xmlrpc.cs @@ -38,6 +38,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected \"0\" or \"1\" as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + string text; try { @@ -84,6 +95,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected a number as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + double result; try { @@ -128,6 +150,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected text as the content of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + try { return reader.ReadContentAsString(); @@ -454,14 +487,16 @@ public static class XmlRpc } else { - key = DeserializeStringTextFrom(reader, out error) - ?? throw new System.InvalidOperationException( - "Unexpected key null when error null"); + string? maybeKey = DeserializeStringTextFrom(reader, out error); if (error != null) { return null; } + key = maybeKey + ?? throw new System.InvalidOperationException( + "Unexpected key null when error null"); + XmlCommon.ConsumeEndElementInNoNamespace( reader, "name", false, out error); if (error != null) diff --git a/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy.Tests/TestXmlRpc.cs b/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy.Tests/TestXmlRpc.cs index 8b64d4c33..f368e3e64 100644 --- a/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy.Tests/TestXmlRpc.cs +++ b/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy.Tests/TestXmlRpc.cs @@ -285,6 +285,33 @@ public void Test_deserialize_rejects_non_strict_boolean_lexical_form() $"Unexpected cause: {error.Cause}"); } + [Test] + public void Test_deserialize_rejects_a_nested_element_in_a_text() + { + string[] texts = + { + "", + "", + "", + "" + + "" + + "something" + + "" + }; + + foreach (string text in texts) + { + Nodes.JsonNode? result = DeserializeFromString( + text, out Our.Reporting.Error? error); + + Assert.IsNull(result, text); + Assert.IsNotNull(error, text); + Assert.IsTrue( + error!.Cause.Contains("but got a nested element nested"), + $"Unexpected cause for {text}: {error.Cause}"); + } + } + [Test] public void Test_deserialize_rejects_repeated_member_key() { diff --git a/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy/xmlrpc.cs b/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy/xmlrpc.cs index 609fc4a50..bbf004467 100644 --- a/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy/xmlrpc.cs +++ b/dev/test_data/main/csharp/expected/json_types_in_invariants/expected_output/dummy/xmlrpc.cs @@ -38,6 +38,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected \"0\" or \"1\" as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + string text; try { @@ -84,6 +95,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected a number as the text of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + double result; try { @@ -128,6 +150,17 @@ public static class XmlRpc { error = null; + // NOTE (mristin): + // XmlReader.ReadContentAsString throws an InvalidOperationException if + // it starts at an element, so we report a nested element beforehand. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + "Expected text as the content of a element, " + + $"but got a nested element {reader.Name}"); + return null; + } + try { return reader.ReadContentAsString(); @@ -454,14 +487,16 @@ public static class XmlRpc } else { - key = DeserializeStringTextFrom(reader, out error) - ?? throw new System.InvalidOperationException( - "Unexpected key null when error null"); + string? maybeKey = DeserializeStringTextFrom(reader, out error); if (error != null) { return null; } + key = maybeKey + ?? throw new System.InvalidOperationException( + "Unexpected key null when error null"); + XmlCommon.ConsumeEndElementInNoNamespace( reader, "name", false, out error); if (error != null) diff --git a/dev/test_data/main/csharp/expected/list_of_classes/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/list_of_classes/expected_output/dummy/xmlization.cs index 45cb451f9..42fa34ed0 100644 --- a/dev/test_data/main/csharp/expected/list_of_classes/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/list_of_classes/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/list_of_constrained_primitives/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/list_of_constrained_primitives/expected_output/dummy/xmlization.cs index c0a82d4bf..0f92ed7c4 100644 --- a/dev/test_data/main/csharp/expected/list_of_constrained_primitives/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/list_of_constrained_primitives/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/list_of_enums/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/list_of_enums/expected_output/dummy/xmlization.cs index 002965384..e41b30473 100644 --- a/dev/test_data/main/csharp/expected/list_of_enums/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/list_of_enums/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/list_of_primitives/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/list_of_primitives/expected_output/dummy/xmlization.cs index 340a15f80..3e4d2e24f 100644 --- a/dev/test_data/main/csharp/expected/list_of_primitives/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/list_of_primitives/expected_output/dummy/xmlization.cs @@ -145,6 +145,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/method_references/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/method_references/expected_output/dummy/xmlization.cs index 881f5d5c8..4fa0d052d 100644 --- a/dev/test_data/main/csharp/expected/method_references/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/method_references/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/nested_any_in_all/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/nested_any_in_all/expected_output/dummy/xmlization.cs index c6ffc36c9..1990ae5c3 100644 --- a/dev/test_data/main/csharp/expected/nested_any_in_all/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/nested_any_in_all/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/nested_collections/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/nested_collections/expected_output/dummy/xmlization.cs index 0fabe1cfc..8bf7bb675 100644 --- a/dev/test_data/main/csharp/expected/nested_collections/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/nested_collections/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/optional_arguments/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/optional_arguments/expected_output/dummy/xmlization.cs index 897aff5ea..f845cbb29 100644 --- a/dev/test_data/main/csharp/expected/optional_arguments/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/optional_arguments/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/primitive_types/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/primitive_types/expected_output/dummy/xmlization.cs index 608026905..6f563739f 100644 --- a/dev/test_data/main/csharp/expected/primitive_types/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/primitive_types/expected_output/dummy/xmlization.cs @@ -145,6 +145,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/problematic_keywords/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/problematic_keywords/expected_output/dummy/xmlization.cs index 397dbc411..422451ac0 100644 --- a/dev/test_data/main/csharp/expected/problematic_keywords/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/problematic_keywords/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/sets/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/sets/expected_output/dummy/xmlization.cs index df3305593..69b5e4063 100644 --- a/dev/test_data/main/csharp/expected/sets/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/sets/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/string_slicing_and_find/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/string_slicing_and_find/expected_output/dummy/xmlization.cs index 163666f0a..503995c0c 100644 --- a/dev/test_data/main/csharp/expected/string_slicing_and_find/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/string_slicing_and_find/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/switch_statements/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/switch_statements/expected_output/dummy/xmlization.cs index 0153cb160..971d89bca 100644 --- a/dev/test_data/main/csharp/expected/switch_statements/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/switch_statements/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/transpiled_methods/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/transpiled_methods/expected_output/dummy/xmlization.cs index d8548a442..d18ff7d8d 100644 --- a/dev/test_data/main/csharp/expected/transpiled_methods/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/transpiled_methods/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/tuples/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/tuples/expected_output/dummy/xmlization.cs index 5243b4137..fe63170c4 100644 --- a/dev/test_data/main/csharp/expected/tuples/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/tuples/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/unions/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/unions/expected_output/dummy/xmlization.cs index 5418a5887..7e1d5a1f9 100644 --- a/dev/test_data/main/csharp/expected/unions/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/unions/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader); diff --git a/dev/test_data/main/csharp/expected/visibility/expected_output/dummy/xmlization.cs b/dev/test_data/main/csharp/expected/visibility/expected_output/dummy/xmlization.cs index 5da216719..952f1987f 100644 --- a/dev/test_data/main/csharp/expected/visibility/expected_output/dummy/xmlization.cs +++ b/dev/test_data/main/csharp/expected/visibility/expected_output/dummy/xmlization.cs @@ -121,6 +121,19 @@ out Reporting.Error? error return default!; } + // NOTE (mristin): + // XmlReader.ReadContentAs* throws an InvalidOperationException if it + // starts at an element, so we have to report a nested element before + // the conversion. A nested element after a text is not our concern + // here, as the caller expects the end element afterwards. + if (reader.NodeType == Xml.XmlNodeType.Element) + { + error = new Reporting.Error( + $"Expected an XML content representing {typeof(T).Name}, " + + $"but got a nested element {reader.Name}"); + return default!; + } + try { return readContent(reader);