📝 clean up

This commit is contained in:
Niels Lohmann 2024-12-22 14:20:10 +01:00
parent e9876d9e46
commit b167096e82
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 8 additions and 5 deletions

View File

@ -28,8 +28,8 @@ and `ensure_ascii` parameters.
: how to react on decoding errors; there are three possible values (see [`error_handler_t`](error_handler_t.md)):
: - `strict`: throws a [`type_error`](../../home/exceptions.md#type-errors) exception in case a decoding error occurs (this is the default),
- `replace`: replace invalid UTF-8 sequences with U+FFFD (<28> REPLACEMENT CHARACTER),
- `ignore`: ignore invalid UTF-8 sequences during serialization, and
- `keep`: keep invalid UTF-8 sequences during serialization; all bytes are copied to the output unchanged
- `ignore`: ignore invalid UTF-8 sequences during serialization (i.e., these bytes are skipped and not copied to the output), and
- `keep`: keep invalid UTF-8 sequences during serialization (i.e., all bytes are copied to the output unchanged)
## Return value

View File

@ -18,7 +18,7 @@ replace
: replace invalid UTF-8 sequences with U+FFFD (<28> REPLACEMENT CHARACTER)
ignore
: ignore invalid UTF-8 sequences
: ignore invalid UTF-8 sequences; these bytes are skipped and not copied to the output
keep
: keep invalid UTF-8 sequences; all bytes are copied to the output unchanged

View File

@ -1000,8 +1000,11 @@ TEST_CASE("regression tests 2")
{
nlohmann::json node;
node["test"] = "test\334\005";
const auto test_dump = node.dump(-1, ' ', false, nlohmann::json::error_handler_t::keep);
CHECK(test_dump == "{\"test\":\"test\334\005\"}");
auto x = node.dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore);
CHECK(node.dump(-1, ' ', false, nlohmann::json::error_handler_t::ignore) == "{\"test\":\"test\\u0005\"}");
CHECK(node.dump(-1, ' ', false, nlohmann::json::error_handler_t::keep) == "{\"test\":\"test\334\005\"}");
CHECK(node.dump(-1, ' ', true, nlohmann::json::error_handler_t::keep) == "{\"test\":\"test\334\005\"}");
}
}