Skip to content

Commit

Permalink
Serialize text kv without utf8 bom
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Jun 4, 2020
1 parent db5463d commit 74dd5d2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions ValveKeyValue/ValveKeyValue.Test/KVSerializerUtf8NoBomTestCase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;
using NUnit.Framework;

namespace ValveKeyValue.Test
{
class KVSerializerUtf8NoBomTestCase
{
[TestCase]
public void TextSerializerDoesNotProduceUtf8Preamble()
{
var dataObject = new DataObject
{
Name = "First"
};

byte[] output;
using (var ms = new MemoryStream())
{
KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, dataObject, "test");

ms.Seek(0, SeekOrigin.Begin);

output = ms.ToArray();
}

Assert.AreEqual((byte)'"', output[0]);
}

class DataObject
{
public string Name { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public KV1TextSerializer(Stream stream, KVSerializerOptions options)
Require.NotNull(options, nameof(options));

this.options = options;
writer = new StreamWriter(stream, Encoding.UTF8, bufferSize: 1024, leaveOpen: true);
writer = new StreamWriter(stream, new UTF8Encoding(), bufferSize: 1024, leaveOpen: true);
writer.NewLine = "\n";
}

Expand Down

0 comments on commit 74dd5d2

Please sign in to comment.