summaryrefslogtreecommitdiff
path: root/src/idl_parser.cpp
diff options
context:
space:
mode:
authorVladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com>2021-03-16 01:44:42 +0700
committerGitHub <noreply@github.com>2021-03-15 11:44:42 -0700
commit69b329fc87e7a10f84a0bd012e74e3af7549526d (patch)
treeb2b9f5927bee600b90cfc0b10cbcc5fc1206199e /src/idl_parser.cpp
parent6543ba5297343986d9e059d05d6a17c81eefb205 (diff)
downloadflatbuffers-69b329fc87e7a10f84a0bd012e74e3af7549526d.tar.gz
flatbuffers-69b329fc87e7a10f84a0bd012e74e3af7549526d.tar.bz2
flatbuffers-69b329fc87e7a10f84a0bd012e74e3af7549526d.zip
[flexbuffers, json] Parse `nan` and `inf` (#6512)
Diffstat (limited to 'src/idl_parser.cpp')
-rw-r--r--src/idl_parser.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index 6faee4d3..f20b6f9a 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -3009,6 +3009,15 @@ CheckedError Parser::SkipAnyJsonValue() {
return NoError();
}
+CheckedError Parser::ParseFlexBufferNumericConstant(
+ flexbuffers::Builder *builder) {
+ double d;
+ if (!StringToNumber(attribute_.c_str(), &d))
+ return Error("unexpected floating-point constant: " + attribute_);
+ builder->Double(d);
+ return NoError();
+}
+
CheckedError Parser::ParseFlexBufferValue(flexbuffers::Builder *builder) {
ParseDepthGuard depth_guard(this);
ECHECK(depth_guard.Check());
@@ -3056,6 +3065,18 @@ CheckedError Parser::ParseFlexBufferValue(flexbuffers::Builder *builder) {
EXPECT(kTokenFloatConstant);
break;
}
+ case '-':
+ case '+': {
+ // `[-+]?(nan|inf|infinity)`, see ParseSingleValue().
+ const auto sign = static_cast<char>(token_);
+ NEXT();
+ if (token_ != kTokenIdentifier)
+ return Error("floating-point constant expected");
+ attribute_.insert(0, 1, sign);
+ ECHECK(ParseFlexBufferNumericConstant(builder));
+ NEXT();
+ break;
+ }
default:
if (IsIdent("true")) {
builder->Bool(true);
@@ -3066,6 +3087,9 @@ CheckedError Parser::ParseFlexBufferValue(flexbuffers::Builder *builder) {
} else if (IsIdent("null")) {
builder->Null();
NEXT();
+ } else if (IsIdent("inf") || IsIdent("infinity") || IsIdent("nan")) {
+ ECHECK(ParseFlexBufferNumericConstant(builder));
+ NEXT();
} else
return TokenError();
}