merge revision(s) 7a05dbc47831a655a1ef8a1635f88292acd325da: [Backport #21561]

File.dirname: return consistent encoding for `"."`

	[Bug #21561]

	It's preferable if the method is consistent in the encoding in
	the returned string.
This commit is contained in:
Takashi Kokubun 2025-09-12 14:58:07 -07:00
parent 00fa53d0ba
commit 21709a5868
2 changed files with 6 additions and 3 deletions

7
file.c
View File

@ -4947,8 +4947,11 @@ rb_file_dirname_n(VALUE fname, int n)
break;
}
}
if (p == name)
return rb_usascii_str_new2(".");
if (p == name) {
dirname = rb_str_new(".", 1);
rb_enc_copy(dirname, fname);
return dirname;
}
#ifdef DOSISH_DRIVE_LETTER
if (has_drive_letter(name) && isdirsep(*(name + 2))) {
const char *top = skiproot(name + 2, end, enc);

View File

@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 5
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
#define RUBY_PATCHLEVEL 53
#define RUBY_PATCHLEVEL 54
#include "ruby/version.h"
#include "ruby/internal/abi.h"