aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-09-29 19:09:32 -0500
committerrogerk <devnull@localhost>2011-09-29 19:09:32 -0500
commit4b75bbe45f544152ca883b573cfb6728a859ab66 (patch)
treedb21881ef351d69810bfa57831e68efea6a464d1
parent353b0fad9042c183de3f874cde072f75a60d8d2a (diff)
downloadprotobuf-4b75bbe45f544152ca883b573cfb6728a859ab66.tar.gz
protobuf-4b75bbe45f544152ca883b573cfb6728a859ab66.tar.bz2
protobuf-4b75bbe45f544152ca883b573cfb6728a859ab66.zip
Fix for incorrect handling of Whitespace after an array open in XmlFormatReader
-rw-r--r--src/ProtocolBuffers.Serialization/XmlFormatReader.cs8
-rw-r--r--src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs18
-rw-r--r--src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs21
-rw-r--r--src/ProtocolBuffers.Test/TestWriterFormatXml.cs8
4 files changed, 51 insertions, 4 deletions
diff --git a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
index bf21db55..20027177 100644
--- a/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
+++ b/src/ProtocolBuffers.Serialization/XmlFormatReader.cs
@@ -315,10 +315,14 @@ namespace Google.ProtocolBuffers.Serialization
}
else
{
+ string found;
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();
}
diff --git a/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs
index fb895040..6b368b7d 100644
--- a/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs
+++ b/src/ProtocolBuffers.Test/Compatibility/JsonCompatibilityTests.cs
@@ -12,6 +12,24 @@ namespace Google.ProtocolBuffers.Compatibility
{
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)
+ {
+ StringWriter sw = new StringWriter();
+ JsonFormatWriter.CreateInstance(sw)
.Formatted()
.WriteMessage(message);
return sw.ToString();
diff --git a/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
index 50ef6f03..62b9456a 100644
--- a/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
+++ b/src/ProtocolBuffers.Test/Compatibility/XmlCompatibilityTests.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Xml;
using Google.ProtocolBuffers.Serialization;
using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework;
@@ -22,4 +23,24 @@ namespace Google.ProtocolBuffers.Compatibility
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
diff --git a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
index 46853582..a52d04e1 100644
--- a/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
+++ b/src/ProtocolBuffers.Test/TestWriterFormatXml.cs
@@ -194,7 +194,9 @@ namespace Google.ProtocolBuffers
.Build();
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();
@@ -221,7 +223,9 @@ namespace Google.ProtocolBuffers
.Build();
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)
.WriteMessage("root", message);