summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2022-10-14 21:46:37 +0200
committerJens Geyer <jensg@apache.org>2022-10-16 12:04:49 +0200
commit0b1e9513b4fd22b0b382d848cff5201d6d94a06a (patch)
treed3c6b56a2c474432e5b42a84bfc0c9f14b7e6ec3 /compiler
parentec0141cc550e3ab7c8abb086e41407d145c44c19 (diff)
downloadthrift-0b1e9513b4fd22b0b382d848cff5201d6d94a06a.tar.gz
THRIFT-5652 IDL uuid literals can be improved
Compiler (general) Patch: Jens Geyer This closes #2714
Diffstat (limited to 'compiler')
-rw-r--r--compiler/cpp/src/thrift/main.cc2
-rw-r--r--compiler/cpp/src/thrift/parse/t_const_value.h24
2 files changed, 16 insertions, 10 deletions
diff --git a/compiler/cpp/src/thrift/main.cc b/compiler/cpp/src/thrift/main.cc
index a07f4295a..485ec0022 100644
--- a/compiler/cpp/src/thrift/main.cc
+++ b/compiler/cpp/src/thrift/main.cc
@@ -742,7 +742,7 @@ void validate_const_rec(std::string name, t_type* type, t_const_value* value) {
if (value->get_type() != t_const_value::CV_STRING) {
throw "type error: const \"" + name + "\" was declared as uuid";
}
- value->get_uuid(); // validates constant
+ value->set_uuid(value->get_uuid()); // validates constant
break;
case t_base_type::TYPE_BOOL:
if (value->get_type() != t_const_value::CV_INTEGER) {
diff --git a/compiler/cpp/src/thrift/parse/t_const_value.h b/compiler/cpp/src/thrift/parse/t_const_value.h
index 452a90c5b..382422ef9 100644
--- a/compiler/cpp/src/thrift/parse/t_const_value.h
+++ b/compiler/cpp/src/thrift/parse/t_const_value.h
@@ -92,8 +92,9 @@ public:
}
std::string get_uuid() const {
- validate_uuid(stringVal_);
- return stringVal_;
+ std::string tmp = stringVal_;
+ validate_uuid(tmp);
+ return tmp;
}
void set_double(double val) {
@@ -210,13 +211,18 @@ private:
t_enum* enum_;
t_const_value_type valType_;
-
- void validate_uuid(std::string uuid) const {
- bool valid = (uuid.length() == 36);
+
+ void validate_uuid(std::string & uuid) const {
const std::string HEXCHARS = std::string("0123456789ABCDEFabcdef");
+ // we also allow for usual "Windows GUID" format "{01234567-9012-4567-9012-456789012345}"
+ if ((uuid.length() == 38) && ('{' == uuid[0]) && ('}' == uuid[37])) {
+ uuid = uuid.substr(1, 36);
+ }
+
// canonical format "01234567-9012-4567-9012-456789012345" expected
- for( size_t i = 0; valid && (i < uuid.length()); ++i) {
+ bool valid = (uuid.length() == 36);
+ for (size_t i = 0; valid && (i < uuid.length()); ++i) {
switch(i) {
case 8:
case 13:
@@ -224,14 +230,14 @@ private:
case 23:
if(uuid[i] != '-') {
valid = false;
- }
+ }
break;
default:
if(HEXCHARS.find(uuid[i]) == std::string::npos) {
valid = false;
- }
+ }
break;
- }
+ }
}
if( ! valid) {