mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
Billy donahue avoid isprint (#1191)
* avoid isprint `std::isprint` is locale-specific and the JSON-spec is not. In particular, isprint('\t') is true in Windows CP1252. Has bitten others, e.g. https://github.com/laurikari/tre/issues/64 Fixes #1187 * semicolon (rookie mistake!) * Windows tab escape testing with custom locale (#1190) Co-authored-by: Nikolay Baklicharov <thestorm.nik@gmail.com>
This commit is contained in:
parent
b3189a0800
commit
632044ad95
@ -2702,6 +2702,34 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, escapeControlCharacters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
JSONTEST_FIXTURE_LOCAL(StreamWriterTest, escapeTabCharacterWindows) {
|
||||||
|
// Get the current locale before changing it
|
||||||
|
std::string currentLocale = setlocale(LC_ALL, NULL);
|
||||||
|
setlocale(LC_ALL, "English_United States.1252");
|
||||||
|
|
||||||
|
Json::Value root;
|
||||||
|
root["test"] = "\tTabTesting\t";
|
||||||
|
|
||||||
|
Json::StreamWriterBuilder b;
|
||||||
|
|
||||||
|
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
|
||||||
|
"\"\\tTabTesting\\t\"\n}");
|
||||||
|
|
||||||
|
b.settings_["emitUTF8"] = true;
|
||||||
|
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
|
||||||
|
"\"\\tTabTesting\\t\"\n}");
|
||||||
|
|
||||||
|
b.settings_["emitUTF8"] = false;
|
||||||
|
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
|
||||||
|
"\"\\tTabTesting\\t\"\n}");
|
||||||
|
|
||||||
|
// Restore the locale
|
||||||
|
if (!currentLocale.empty())
|
||||||
|
setlocale(LC_ALL, currentLocale.c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ReaderTest : JsonTest::TestCase {
|
struct ReaderTest : JsonTest::TestCase {
|
||||||
void setStrictMode() {
|
void setStrictMode() {
|
||||||
reader = std::unique_ptr<Json::Reader>(
|
reader = std::unique_ptr<Json::Reader>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user