Skip to content

Commit 632044a

Browse files
Billy donahue avoid isprint (open-source-parsers#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. laurikari/tre#64 Fixes open-source-parsers#1187 * semicolon (rookie mistake!) * Windows tab escape testing with custom locale (open-source-parsers#1190) Co-authored-by: Nikolay Baklicharov <[email protected]>
1 parent b3189a0 commit 632044a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test_lib_json/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,34 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, escapeControlCharacters) {
27022702
}
27032703
}
27042704

2705+
#ifdef _WIN32
2706+
JSONTEST_FIXTURE_LOCAL(StreamWriterTest, escapeTabCharacterWindows) {
2707+
// Get the current locale before changing it
2708+
std::string currentLocale = setlocale(LC_ALL, NULL);
2709+
setlocale(LC_ALL, "English_United States.1252");
2710+
2711+
Json::Value root;
2712+
root["test"] = "\tTabTesting\t";
2713+
2714+
Json::StreamWriterBuilder b;
2715+
2716+
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
2717+
"\"\\tTabTesting\\t\"\n}");
2718+
2719+
b.settings_["emitUTF8"] = true;
2720+
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
2721+
"\"\\tTabTesting\\t\"\n}");
2722+
2723+
b.settings_["emitUTF8"] = false;
2724+
JSONTEST_ASSERT(Json::writeString(b, root) == "{\n\t\"test\" : "
2725+
"\"\\tTabTesting\\t\"\n}");
2726+
2727+
// Restore the locale
2728+
if (!currentLocale.empty())
2729+
setlocale(LC_ALL, currentLocale.c_str());
2730+
}
2731+
#endif
2732+
27052733
struct ReaderTest : JsonTest::TestCase {
27062734
void setStrictMode() {
27072735
reader = std::unique_ptr<Json::Reader>(

0 commit comments

Comments
 (0)