Backport #8165 ยป 0001-load.c-fix-require-with-non-ascii-path.patch
internal.h | ||
---|---|---|
295 | 295 |
int rb_str_symname_p(VALUE); |
296 | 296 |
VALUE rb_str_quote_unprintable(VALUE); |
297 | 297 |
VALUE rb_id_quote_unprintable(ID); |
298 |
VALUE rb_str_subseq_without_enc(VALUE, long, long); |
|
298 | 299 |
#define QUOTE(str) rb_str_quote_unprintable(str) |
299 | 300 |
#define QUOTE_ID(id) rb_id_quote_unprintable(id) |
300 | 301 |
load.c | ||
---|---|---|
247 | 247 |
if (p < feature_str) |
248 | 248 |
break; |
249 | 249 |
/* Now *p == '/'. We reach this point for every '/' in `feature`. */ |
250 |
short_feature = rb_str_substr(feature, p + 1 - feature_str, feature_end - p - 1);
|
|
250 |
short_feature = rb_str_subseq_without_enc(feature, p + 1 - feature_str, feature_end - p - 1);
|
|
251 | 251 |
features_index_add_single(short_feature, offset); |
252 | 252 |
if (ext) { |
253 |
short_feature = rb_str_substr(feature, p + 1 - feature_str, ext - p - 1);
|
|
253 |
short_feature = rb_str_subseq_without_enc(feature, p + 1 - feature_str, ext - p - 1);
|
|
254 | 254 |
features_index_add_single(short_feature, offset); |
255 | 255 |
} |
256 | 256 |
} |
257 | 257 |
features_index_add_single(feature, offset); |
258 | 258 |
if (ext) { |
259 |
short_feature = rb_str_substr(feature, 0, ext - feature_str);
|
|
259 |
short_feature = rb_str_subseq_without_enc(feature, 0, ext - feature_str);
|
|
260 | 260 |
features_index_add_single(short_feature, offset); |
261 | 261 |
} |
262 | 262 |
} |
string.c | ||
---|---|---|
1667 | 1667 |
} |
1668 | 1668 | |
1669 | 1669 |
VALUE |
1670 |
rb_str_subseq(VALUE str, long beg, long len) |
|
1670 |
rb_str_subseq_without_enc(VALUE str, long beg, long len)
|
|
1671 | 1671 |
{ |
1672 | 1672 |
VALUE str2; |
1673 | 1673 | |
... | ... | |
1681 | 1681 |
RB_GC_GUARD(str); |
1682 | 1682 |
} |
1683 | 1683 | |
1684 |
rb_enc_cr_str_copy_for_substr(str2, str); |
|
1685 | 1684 |
OBJ_INFECT(str2, str); |
1686 | 1685 | |
1687 | 1686 |
return str2; |
1688 | 1687 |
} |
1689 | 1688 | |
1689 |
VALUE |
|
1690 |
rb_str_subseq(VALUE str, long beg, long len) |
|
1691 |
{ |
|
1692 |
VALUE str2 = rb_str_subseq_without_enc(str, beg, len); |
|
1693 | ||
1694 |
rb_enc_cr_str_copy_for_substr(str2, str); |
|
1695 | ||
1696 |
return str2; |
|
1697 |
} |
|
1698 | ||
1690 | 1699 |
static char * |
1691 | 1700 |
rb_str_subpos(VALUE str, long beg, long *lenp) |
1692 | 1701 |
{ |
test/ruby/test_require.rb | ||
---|---|---|
639 | 639 |
ensure |
640 | 640 |
script.close(true) if script |
641 | 641 |
end |
642 | ||
643 |
def test_require_with_non_ascii_path |
|
644 |
bug8165 = '[ruby-core:53733] [Bug #8165]' |
|
645 |
Dir.mktmpdir {|tmp| |
|
646 |
Dir.chdir(tmp) { |
|
647 |
dir = "\u3042" * 5 |
|
648 |
Dir.mkdir(dir) |
|
649 |
path = File.join(tmp, dir, 'foo.rb').force_encoding('UTF-8') |
|
650 |
open(path, "w") {|f| |
|
651 |
f.puts "p :ok" |
|
652 |
} |
|
653 |
assert_in_out_err([], <<-INPUT, %w(:ok), [], bug8165) |
|
654 |
# coding: UTF-8 |
|
655 |
$:.replace([IO::NULL]) |
|
656 |
require '#{path}' |
|
657 |
p :ng if require '#{path}' |
|
658 |
INPUT |
|
659 |
} |
|
660 |
} |
|
661 |
end |
|
642 | 662 |
end |
643 |
- |