Merge pull request #230 from arp242/t

Escape control characters in keys
This commit is contained in:
Toru Niina 2023-10-10 23:21:43 +09:00 committed by GitHub
commit 22d96ed921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,7 +63,19 @@ format_key(const std::basic_string<charT, traits, Alloc>& k)
case '\f': {serialized += "\\f"; break;} case '\f': {serialized += "\\f"; break;}
case '\n': {serialized += "\\n"; break;} case '\n': {serialized += "\\n"; break;}
case '\r': {serialized += "\\r"; break;} case '\r': {serialized += "\\r"; break;}
default : {serialized += c; break;} default: {
if (c >= 0x00 && c < 0x20)
{
std::array<char, 7> buf;
std::snprintf(buf.data(), buf.size(), "\\u00%02x", static_cast<int>(c));
serialized += buf.data();
}
else
{
serialized += c;
}
break;
}
} }
} }
serialized += "\""; serialized += "\"";