Skip to content

Commit

Permalink
Fix #155 don't use ion escaping in JSON mode (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderNate committed May 1, 2024
1 parent dbdc143 commit e8b6e66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Amazon.IonDotnet.Tests/Internals/TextWriterJsonTest.cs
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion Amazon.IonDotnet/Internals/Text/IonTextWriter.cs
Expand Up @@ -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();
Expand Down

0 comments on commit e8b6e66

Please sign in to comment.