Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b429873

Browse files
committed
Merge pull request #2053 from khdang/fix-exception-message-differences
Fix exception message differences when deserializing empty string
2 parents 9b24cf6 + 10b877b commit b429873

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryReader.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ static public XmlDictionaryReader CreateTextReader(byte[] buffer, int offset, in
9494

9595
static public XmlDictionaryReader CreateTextReader(Stream stream, XmlDictionaryReaderQuotas quotas)
9696
{
97-
XmlReaderSettings readerSettings = new XmlReaderSettings();
98-
readerSettings.CheckCharacters = false;
99-
XmlReader reader = XmlReader.Create(stream, readerSettings);
100-
return XmlDictionaryReader.CreateDictionaryReader(reader);
97+
return CreateTextReader(stream, null, quotas, null);
10198
}
10299

103100
static public XmlDictionaryReader CreateTextReader(Stream stream, Encoding encoding,

src/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,16 @@ public static void DCJS_SerializationEvents()
12711271
Assert.True(output.OnDeserializedMethodInvoked, "output.OnDeserializedMethodInvoked is false");
12721272
}
12731273

1274+
[Fact]
1275+
public static void DCJS_DeserializeEmptyString()
1276+
{
1277+
var serializer = new DataContractJsonSerializer(typeof (object));
1278+
Assert.Throws<SerializationException>(() =>
1279+
{
1280+
serializer.ReadObject(new MemoryStream());
1281+
});
1282+
}
1283+
12741284
private static T SerializeAndDeserialize<T>(T value, string baseline, DataContractJsonSerializerSettings settings = null, Func<DataContractJsonSerializer> serializerFactory = null)
12751285
{
12761286
DataContractJsonSerializer dcjs;

src/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,16 @@ public static void DCS_DerivedException()
17031703
Assert.StrictEqual(value.TestProperty, actual.TestProperty);
17041704
}
17051705

1706+
[Fact]
1707+
public static void DCS_DeserializeEmptyString()
1708+
{
1709+
var serializer = new DataContractSerializer(typeof (object));
1710+
Assert.Throws<XmlException>(() =>
1711+
{
1712+
serializer.ReadObject(new MemoryStream());
1713+
});
1714+
}
1715+
17061716
private static T SerializeAndDeserialize<T>(T value, string baseline, DataContractSerializerSettings settings = null, Func<DataContractSerializer> serializerFactory = null)
17071717
{
17081718
DataContractSerializer dcs;

0 commit comments

Comments
 (0)