Skip to content

Commit

Permalink
Merge pull request #146 from robertmrk/surrogate-pair-parsing-fix
Browse files Browse the repository at this point in the history
Fix character skipping after a surrogate pair
  • Loading branch information
nlohmann committed Nov 14, 2015
2 parents 3948630 + ec7a1d8 commit c013223
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6856,8 +6856,8 @@ class basic_json
auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
(i + 7), 4).c_str(), nullptr, 16);
result += to_unicode(codepoint, codepoint2);
// skip the next 11 characters (xxxx\uyyyy)
i += 11;
// skip the next 10 characters (xxxx\uyyyy)
i += 10;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -6162,8 +6162,8 @@ class basic_json
auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
(i + 7), 4).c_str(), nullptr, 16);
result += to_unicode(codepoint, codepoint2);
// skip the next 11 characters (xxxx\uyyyy)
i += 11;
// skip the next 10 characters (xxxx\uyyyy)
i += 10;
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10205,4 +10205,9 @@ TEST_CASE("regression tests")
j["string"] = bytes;
CHECK(j["string"] == "\u0007\u0007");
}

SECTION("character following a surrogate pair is skipped")
{
CHECK(json::parse("\"\\ud80c\\udc60abc\"").get<json::string_t>() == u8"\U00013060abc");
}
}

0 comments on commit c013223

Please sign in to comment.