mirror of
https://github.com/nlohmann/json.git
synced 2026-09-07 08:47:57 +00:00
Fix MSVC source-encoding portability in the wide-string position test
Use é escapes instead of a literal UTF-8-encoded 'é' inside the L"" literal, so the wide string's content does not depend on the compiler's assumed source character set (MSVC without /utf-8 decodes raw non-ASCII source bytes using the system code page rather than as UTF-8, which was producing a wstring of unexpected length/content and failing the ws.size()/end_pos() assertions on Windows CI). Also reworded a comment that unintentionally embedded the literal substring "TODO check", which clang-tidy's google-readability-todo check flags regardless of quoting context. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -2195,9 +2195,10 @@ TEST_CASE("diagnostic positions: value lifetime, input adapters, and SAX")
|
||||
{
|
||||
// basic_json(basic_json&&) (json.hpp, around line 1265) copies
|
||||
// other's start_position/end_position into *this and then resets
|
||||
// other's to npos (see the "// cppcheck-suppress[accessForwarded]
|
||||
// TODO check" comments there). Only the top-level moved-from value
|
||||
// is affected; its (moved-away) children are gone along with it.
|
||||
// other's to npos (see the cppcheck-suppress[accessForwarded]
|
||||
// annotation there, which flags this reset as worth a second
|
||||
// look). Only the top-level moved-from value is affected; its
|
||||
// (moved-away) children are gone along with it.
|
||||
const std::string s = R"({"a":1,"b":[1,2,3]})";
|
||||
json a = json::parse(s);
|
||||
const auto a_start = a.start_pos();
|
||||
@@ -2346,7 +2347,12 @@ TEST_CASE("diagnostic positions: value lifetime, input adapters, and SAX")
|
||||
// transcoded UTF-8 byte stream, so reported positions are byte
|
||||
// offsets into that UTF-8 stream, not indices into the original
|
||||
// std::wstring.
|
||||
const std::wstring ws = L"{\"a\":\"éé\"}";
|
||||
// é (rather than a literal 'é' byte sequence in this source
|
||||
// file) so the wide-string literal's meaning does not depend on
|
||||
// the compiler's assumed source character set (MSVC, without
|
||||
// /utf-8, would otherwise decode the raw UTF-8 bytes using the
|
||||
// system code page instead of as UTF-8)
|
||||
const std::wstring ws = L"{\"a\":\"\u00e9\u00e9\"}";
|
||||
CHECK(ws.size() == 10); // 10 wide characters
|
||||
|
||||
const json j = json::parse(ws);
|
||||
|
||||
Reference in New Issue
Block a user