Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f021bef

Browse files
authored
compiler: Avoid compile error on weird proto file names
This only matters when `@generated=javax` is used, so it shouldn't matter much. It isn't guaranteed that javac will interpret the file as UTF-8, but it is exceedingly common, and it doesn't seem too much to ask if you are using weird file names.
1 parent 08e7e9d commit f021bef

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
4747
]
4848
# GRPC_DEPS_END
4949

50+
bazel_dep(name = "abseil-cpp", version = "20250512.1")
5051
bazel_dep(name = "bazel_jar_jar", version = "0.1.11.bcr.1")
5152
bazel_dep(name = "bazel_skylib", version = "1.7.1")
5253
bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis")

compiler/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cc_binary(
1313
],
1414
visibility = ["//visibility:public"],
1515
deps = [
16+
"@abseil-cpp//absl/strings",
1617
"@com_google_protobuf//:protoc_lib",
1718
],
1819
)

compiler/src/java_plugin/cpp/java_generator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <map>
4747
#include <set>
4848
#include <vector>
49+
#include "absl/strings/escaping.h"
4950
#include <google/protobuf/descriptor.h>
5051
#include <google/protobuf/descriptor.pb.h>
5152
#include <google/protobuf/io/printer.h>
@@ -1206,7 +1207,7 @@ static void PrintService(const ServiceDescriptor* service,
12061207
bool disable_version,
12071208
GeneratedAnnotation generated_annotation) {
12081209
(*vars)["service_name"] = service->name();
1209-
(*vars)["file_name"] = service->file()->name();
1210+
(*vars)["file_name"] = absl::Utf8SafeCEscape(service->file()->name());
12101211
(*vars)["service_class_name"] = ServiceClassName(service);
12111212
(*vars)["grpc_version"] = "";
12121213
#ifdef GRPC_VERSION

0 commit comments

Comments
 (0)