Commit 6c4a2de7 authored by csharptest's avatar csharptest Committed by rogerk

Issue 50: The XML serializer will fail to deserialize a message with empty child message

parent cf698798
......@@ -225,15 +225,18 @@ namespace Google.ProtocolBuffers.Serialization
stopNode = _elements.Peek();
}
while (!_input.IsStartElement() && _input.Depth > stopNode.Depth && _input.Read())
if (!stopNode.IsEmpty)
{
continue;
}
while (!_input.IsStartElement() && _input.Depth > stopNode.Depth && _input.Read())
{
continue;
}
if (_input.IsStartElement())
{
field = _input.LocalName;
return true;
if (_input.IsStartElement() && _input.Depth > stopNode.Depth)
{
field = _input.LocalName;
return true;
}
}
field = null;
return false;
......
......@@ -25,6 +25,40 @@ namespace Google.ProtocolBuffers.Compatibility
Assert.AreEqual<object>(lhs, rhs);
}
[TestMethod]
public virtual void RoundTripWithEmptyChildMessageSize()
{
SizeMessage1 msg = SizeMessage1.CreateBuilder()
.SetField100(100)
.SetField15(SizeMessage1SubMessage.DefaultInstance)
.BuildPartial();
byte[] contents = msg.ToByteArray();
object content = SerializeMessage<SizeMessage1, SizeMessage1.Builder>(msg);
SizeMessage1 copy = DeserializeMessage<SizeMessage1, SizeMessage1.Builder>(content, SizeMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SizeMessage1, SizeMessage1.Builder>(copy));
Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
[TestMethod]
public virtual void RoundTripWithEmptyChildMessageSpeed()
{
SpeedMessage1 msg = SpeedMessage1.CreateBuilder()
.SetField100(100)
.SetField15(SpeedMessage1SubMessage.DefaultInstance)
.BuildPartial();
byte[] contents = msg.ToByteArray();
object content = SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(msg);
SpeedMessage1 copy = DeserializeMessage<SpeedMessage1, SpeedMessage1.Builder>(content, SpeedMessage1.CreateBuilder(), ExtensionRegistry.Empty).BuildPartial();
Assert.AreEqual(msg, copy);
AssertOutputEquals(content, SerializeMessage<SpeedMessage1, SpeedMessage1.Builder>(copy));
Assert.AreEqual(Convert.ToBase64String(contents), Convert.ToBase64String(copy.ToByteArray()));
}
[TestMethod]
public virtual void RoundTripMessage1OptimizeSize()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment