From b58a93b8ddd57c1ec03556f9799f3c31b8a019a5 Mon Sep 17 00:00:00 2001
From: Niels <niels.lohmann@gmail.com>
Date: Fri, 14 Aug 2015 14:45:13 +0200
Subject: [PATCH] merged #111

---
 README.md         | 1 +
 src/json.hpp      | 2 ++
 src/json.hpp.re2c | 2 ++
 test/unit.cpp     | 8 ++++++++
 4 files changed, 13 insertions(+)

diff --git a/README.md b/README.md
index d4026dfa..f337bf63 100644
--- a/README.md
+++ b/README.md
@@ -373,6 +373,7 @@ I deeply appreciate the help of the following people.
 - [易思龙](https://github.com/likebeta) implemented a conversion from anonymous enums.
 - [kepkin](https://github.com/kepkin) patiently pushed forward the support for Microsoft Visual studio.
 - [gregmarr](https://github.com/gregmarr) simplified the implementation of reverse iterators.
+- [Caio Luppi](https://github.com/caiovlp) fixed a bug in the Unicode handling.
 
 Thanks a lot for helping out!
 
diff --git a/src/json.hpp b/src/json.hpp
index 993d12e2..bdea958f 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -4692,6 +4692,8 @@ class basic_json
                         // print character c as \uxxxx
                         sprintf(&result[pos + 1], "u%04x", int(c));
                         pos += 6;
+                        // overwrite trailing null character
+                        result[pos] = '\\';
                     }
                     else
                     {
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index 8c24f58e..af8ef8b7 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -4692,6 +4692,8 @@ class basic_json
                         // print character c as \uxxxx
                         sprintf(&result[pos + 1], "u%04x", int(c));
                         pos += 6;
+                        // overwrite trailing null character
+                        result[pos] = '\\';
                     }
                     else
                     {
diff --git a/test/unit.cpp b/test/unit.cpp
index d866b96d..dcf61693 100644
--- a/test/unit.cpp
+++ b/test/unit.cpp
@@ -10194,4 +10194,12 @@ TEST_CASE("regression tests")
         // hexadecimal "a"
         CHECK(j.dump() == "{\"binary string\":\"\\u0000asdf\\n\",\"int64\":10}");
     }
+
+    SECTION("issue #111 - subsequent unicode chars")
+    {
+        std::string bytes{0x7, 0x7};
+        json j;
+        j["string"] = bytes;
+        CHECK(j["string"] == "\u0007\u0007");
+    }
 }