Commit 4b75bbe4 authored by csharptest's avatar csharptest Committed by rogerk

Fix for incorrect handling of Whitespace after an array open in XmlFormatReader

parent 353b0fad
...@@ -315,10 +315,14 @@ namespace Google.ProtocolBuffers.Serialization ...@@ -315,10 +315,14 @@ namespace Google.ProtocolBuffers.Serialization
} }
else else
{ {
string found;
ReadMessageStart(field); ReadMessageStart(field);
foreach (string item in NonNestedArrayItems("item")) if (PeekNext(out found) && found == "item")
{ {
yield return item; foreach (string item in NonNestedArrayItems("item"))
{
yield return item;
}
} }
ReadMessageEnd(); ReadMessageEnd();
} }
......
...@@ -7,6 +7,24 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -7,6 +7,24 @@ namespace Google.ProtocolBuffers.Compatibility
{ {
[TestFixture] [TestFixture]
public class JsonCompatibilityTests : CompatibilityTests public class JsonCompatibilityTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
{
StringWriter sw = new StringWriter();
JsonFormatWriter.CreateInstance(sw)
.WriteMessage(message);
return sw.ToString();
}
protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
{
JsonFormatReader.CreateInstance((string)message).Merge(builder);
return builder;
}
}
[TestFixture]
public class JsonCompatibilityFormattedTests : CompatibilityTests
{ {
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message) protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
{ {
......
using System.IO; using System.IO;
using System.Xml;
using Google.ProtocolBuffers.Serialization; using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; using NUnit.Framework;
...@@ -22,4 +23,24 @@ namespace Google.ProtocolBuffers.Compatibility ...@@ -22,4 +23,24 @@ namespace Google.ProtocolBuffers.Compatibility
return reader.Merge("root", builder, registry); return reader.Merge("root", builder, registry);
} }
} }
[TestFixture]
public class XmlCompatibilityFormattedTests : CompatibilityTests
{
protected override object SerializeMessage<TMessage, TBuilder>(TMessage message)
{
StringWriter text = new StringWriter();
XmlWriter xwtr = XmlWriter.Create(text, new XmlWriterSettings { Indent = true, IndentChars = " " });
XmlFormatWriter writer = XmlFormatWriter.CreateInstance(xwtr).SetOptions(XmlWriterOptions.OutputNestedArrays);
writer.WriteMessage("root", message);
return text.ToString();
}
protected override TBuilder DeserializeMessage<TMessage, TBuilder>(object message, TBuilder builder, ExtensionRegistry registry)
{
XmlFormatReader reader = XmlFormatReader.CreateInstance((string)message).SetOptions(XmlReaderOptions.ReadNestedArrays);
return reader.Merge("root", builder, registry);
}
}
} }
\ No newline at end of file
...@@ -194,7 +194,9 @@ namespace Google.ProtocolBuffers ...@@ -194,7 +194,9 @@ namespace Google.ProtocolBuffers
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
XmlFormatWriter.CreateInstance(sw).WriteMessage("root", message); XmlWriter xwtr = XmlWriter.Create(sw, new XmlWriterSettings {Indent = true, IndentChars = " "});
XmlFormatWriter.CreateInstance(xwtr).WriteMessage("root", message);
string xml = sw.ToString(); string xml = sw.ToString();
...@@ -221,7 +223,9 @@ namespace Google.ProtocolBuffers ...@@ -221,7 +223,9 @@ namespace Google.ProtocolBuffers
.Build(); .Build();
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
XmlFormatWriter.CreateInstance(sw) XmlWriter xwtr = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true, IndentChars = " " });
XmlFormatWriter.CreateInstance(xwtr)
.SetOptions(XmlWriterOptions.OutputNestedArrays | XmlWriterOptions.OutputEnumValues) .SetOptions(XmlWriterOptions.OutputNestedArrays | XmlWriterOptions.OutputEnumValues)
.WriteMessage("root", message); .WriteMessage("root", message);
......
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