From e7ea38652b0205bedf80794a0a19318359a090e3 Mon Sep 17 00:00:00 2001 From: majiang Date: Sat, 24 Feb 2018 19:45:36 +0900 Subject: [PATCH] Do not emit BOM for UTF-8 (Solve #88) (#89) Do not emit BOM for UTF-8 (Solve #88) merged-on-behalf-of: BBasile --- source/dyaml/emitter.d | 3 +-- source/dyaml/stream.d | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/dyaml/emitter.d b/source/dyaml/emitter.d index f00b811..cbe1177 100644 --- a/source/dyaml/emitter.d +++ b/source/dyaml/emitter.d @@ -1177,11 +1177,10 @@ struct Emitter void writeStreamStart() @system { immutable(ubyte)[] bom; - //Write BOM (always, even for UTF-8) + //Write BOM (except for UTF-8) final switch(encoding_) { case Encoding.UTF_8: - bom = ByteOrderMarks[BOM.UTF8]; break; case Encoding.UTF_16: bom = std.system.endian == Endian.littleEndian diff --git a/source/dyaml/stream.d b/source/dyaml/stream.d index 6a5ac00..eb58032 100644 --- a/source/dyaml/stream.d +++ b/source/dyaml/stream.d @@ -134,3 +134,18 @@ unittest // Clean up. remove("output.yaml"); } + +unittest // #88, #89 +{ + import dyaml.dumper, dyaml.loader; + import std.file : remove, read; + + enum fn = "output.yaml"; + scope (exit) fn.remove; + + auto dumper = Dumper(fn); + dumper.YAMLVersion = null; // supress directive + dumper.dump(Loader.fromString("Hello world".dup).load); + + assert (cast (char[]) fn.read()[0..3] == "Hel"); +}