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(
139139 FileDescriptorProtoOrBuilder file , boolean useOldOuterClassnameDefault ) {
140140 // Replicates the logic of ClassNameResolver::GetFileDefaultImmutableClassName.
141141 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 );
143144 name = underscoresToCamelCase (stripProto (name ));
144145 return useOldOuterClassnameDefault ? name : name + "Proto" ;
145146 }
Original file line number Diff line number Diff line change @@ -234,6 +234,15 @@ public void getFileClassName_weirdExtension() {
234234 .isEqualTo ("BarNotproto" );
235235 }
236236
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+
237246 @ Test
238247 public void getFileClassName_conflictingName2024 () {
239248 // 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