File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
main/java/com/google/protobuf
test/java/com/google/protobuf Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -139,7 +139,8 @@ static String getDefaultFileClassName(
139
139
FileDescriptorProtoOrBuilder file , boolean useOldOuterClassnameDefault ) {
140
140
// Replicates the logic of ClassNameResolver::GetFileDefaultImmutableClassName.
141
141
String name = file .getName ();
142
- name = name .substring (name .lastIndexOf ('/' ));
142
+ // The `+ 1` includes the case where no '/' is present.
143
+ name = name .substring (name .lastIndexOf ('/' ) + 1 );
143
144
name = underscoresToCamelCase (stripProto (name ));
144
145
return useOldOuterClassnameDefault ? name : name + "Proto" ;
145
146
}
Original file line number Diff line number Diff line change @@ -234,6 +234,15 @@ public void getFileClassName_weirdExtension() {
234
234
.isEqualTo ("BarNotproto" );
235
235
}
236
236
237
+ @ Test
238
+ public void getFileClassName_noDirectory () {
239
+ // This isn't exercisable in blazel because all our tests are in a directory.
240
+ assertThat (
241
+ GeneratorNames .getFileClassName (
242
+ FileDescriptorProto .newBuilder ().setName ("bar.proto" ).build ()))
243
+ .isEqualTo ("Bar" );
244
+ }
245
+
237
246
@ Test
238
247
public void getFileClassName_conflictingName2024 () {
239
248
// This isn't exercisable in blazel because conflicts trigger a protoc error in edition 2024.
You can’t perform that action at this time.
0 commit comments