From aef178208282310df92aad17ee617165e7227f51 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Thu, 18 Jul 2024 03:20:40 +0200 Subject: [PATCH] THRIFT-5795 namespace not properly escaped Client: netstd Patch: Jens Geyer --- .../src/thrift/generate/t_netstd_generator.cc | 15 +++++++++- ...rift.PublicInterfaces.Compile.Tests.csproj | 1 + .../Thrift5795.thrift | 28 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5795.thrift diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc index aa570ec7f0f..9299ed0f46e 100644 --- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc @@ -314,7 +314,20 @@ void t_netstd_generator::start_netstd_namespace(ostream& out) { if (!namespace_name_.empty()) { - out << "namespace " << namespace_name_ << '\n'; + std::string normalized; + + char* str = strdup(namespace_name_.c_str()); + char* delim = "."; + char* next = strtok(str, delim); + while( next != NULL) { + if( normalized.length() > 0) { + normalized += "."; + } + normalized += normalize_name(next,false); + next = strtok(NULL, delim); + } + + out << "namespace " << normalized << '\n'; scope_up(out); } } diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj index e96d2fe3ac8..9b771d96e83 100644 --- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj @@ -77,6 +77,7 @@ + diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5795.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5795.thrift new file mode 100644 index 00000000000..7bad8d76a7b --- /dev/null +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5795.thrift @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// Testcase for THRIFT-5795 namespace not properly escaped + +namespace * Thrift5795.default + + +struct foo { + 1: double bar; +} +