summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWouter van Oortmerssen <aardappel@gmail.com>2022-02-14 11:28:31 -0800
committerWouter van Oortmerssen <aardappel@gmail.com>2022-02-14 11:28:31 -0800
commitd5add9fca56899aa9f98125be076cbd0fb5819ae (patch)
tree706c58d0009abeb02517a14147c479725e6d733b
parent15df50eb7f37a40fbb2ee919ae11243643d0cd23 (diff)
downloadflatbuffers-d5add9fca56899aa9f98125be076cbd0fb5819ae.tar.gz
flatbuffers-d5add9fca56899aa9f98125be076cbd0fb5819ae.tar.bz2
flatbuffers-d5add9fca56899aa9f98125be076cbd0fb5819ae.zip
Fixed FlexBuffers ToString unquoted non-ident keys
Change-Id: I0a17ee292c9eebbb1e9b2530c07d37d63b4dda24
-rw-r--r--include/flatbuffers/flexbuffers.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h
index a8d58d8b..b4b0332b 100644
--- a/include/flatbuffers/flexbuffers.h
+++ b/include/flatbuffers/flexbuffers.h
@@ -572,7 +572,23 @@ class Reference {
auto keys = m.Keys();
auto vals = m.Values();
for (size_t i = 0; i < keys.size(); i++) {
- keys[i].ToString(true, keys_quoted, s);
+ bool kq = keys_quoted;
+ if (!kq) {
+ // FlexBuffers keys may contain arbitrary characters, only allow
+ // unquoted if it looks like an "identifier":
+ const char *p = keys[i].AsKey();
+ if (!flatbuffers::is_alpha(*p) && *p != '_') {
+ kq = true;
+ } else {
+ while (*++p) {
+ if (!flatbuffers::is_alnum(*p) && *p != '_') {
+ kq = true;
+ break;
+ }
+ }
+ }
+ }
+ keys[i].ToString(true, kq, s);
s += ": ";
vals[i].ToString(true, keys_quoted, s);
if (i < keys.size() - 1) s += ", ";