diff --git a/Amazon.IonDotnet.Tests/Internals/TextWriterJsonTest.cs b/Amazon.IonDotnet.Tests/Internals/TextWriterJsonTest.cs index 2187947..8a6ed66 100644 --- a/Amazon.IonDotnet.Tests/Internals/TextWriterJsonTest.cs +++ b/Amazon.IonDotnet.Tests/Internals/TextWriterJsonTest.cs @@ -188,6 +188,16 @@ public void TestMinutePrecisionTimestampUtc() Assert.AreEqual("{\"value\":\"2010-06-15T03:30Z\"}", this.sw.ToString()); } + [TestMethod] + public void TestStringEscapingDoesntUseShortForm() + { + value.SetField("value", factory.NewString("--" + (char)0x1f + "--")); + var reader = IonReaderBuilder.Build(value); + jsonWriter.WriteValues(reader); + // Json doesn't support the shorter \xNN form, only \uNNNN + Assert.AreEqual("{\"value\":\"--\\u001f--\"}", this.sw.ToString()); + } + [TestMethod] [ExpectedException(typeof(NotSupportedException))] public void TestClob() diff --git a/Amazon.IonDotnet/Internals/Text/IonTextWriter.cs b/Amazon.IonDotnet/Internals/Text/IonTextWriter.cs index 57ed571..71f26fc 100644 --- a/Amazon.IonDotnet/Internals/Text/IonTextWriter.cs +++ b/Amazon.IonDotnet/Internals/Text/IonTextWriter.cs @@ -263,7 +263,12 @@ public override void WriteTimestamp(Timestamp value) public override void WriteString(string value) { this.StartValue(); - if (value != null && !this.followingLongString && this.options.LongStringThreshold < value.Length) + if (this.options.JsonDowngrade) + { + this.textWriter.WriteJsonString(value); + this.CloseValue(); + } + else if (value != null && !this.followingLongString && this.options.LongStringThreshold < value.Length) { this.textWriter.WriteLongString(value); this.CloseValue();