[Bug #20984] ENV.inspect should be encoding aware
This commit is contained in:
parent
037bffec07
commit
19c39e4cfa
Notes:
git
2024-12-26 05:23:42 +00:00
13
hash.c
13
hash.c
@ -5909,24 +5909,23 @@ env_to_s(VALUE _)
|
|||||||
static VALUE
|
static VALUE
|
||||||
env_inspect(VALUE _)
|
env_inspect(VALUE _)
|
||||||
{
|
{
|
||||||
VALUE i;
|
|
||||||
VALUE str = rb_str_buf_new2("{");
|
VALUE str = rb_str_buf_new2("{");
|
||||||
|
rb_encoding *enc = env_encoding();
|
||||||
|
|
||||||
ENV_LOCK();
|
ENV_LOCK();
|
||||||
{
|
{
|
||||||
char **env = GET_ENVIRON(environ);
|
char **env = GET_ENVIRON(environ);
|
||||||
while (*env) {
|
while (*env) {
|
||||||
char *s = strchr(*env, '=');
|
const char *s = strchr(*env, '=');
|
||||||
|
|
||||||
if (env != environ) {
|
if (env != environ) {
|
||||||
rb_str_buf_cat2(str, ", ");
|
rb_str_buf_cat2(str, ", ");
|
||||||
}
|
}
|
||||||
if (s) {
|
if (s) {
|
||||||
rb_str_buf_cat2(str, "\"");
|
rb_str_buf_append(str, rb_str_inspect(env_enc_str_new(*env, s-*env, enc)));
|
||||||
rb_str_buf_cat(str, *env, s-*env);
|
rb_str_buf_cat2(str, "=>");
|
||||||
rb_str_buf_cat2(str, "\"=>");
|
s++;
|
||||||
i = rb_inspect(rb_str_new2(s+1));
|
rb_str_buf_append(str, rb_str_inspect(env_enc_str_new(s, strlen(s), enc)));
|
||||||
rb_str_buf_append(str, i);
|
|
||||||
}
|
}
|
||||||
env++;
|
env++;
|
||||||
}
|
}
|
||||||
|
@ -357,6 +357,13 @@ class TestEnv < Test::Unit::TestCase
|
|||||||
assert_equal(expected, s)
|
assert_equal(expected, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_inspect_encoding
|
||||||
|
ENV.clear
|
||||||
|
key = "VAR\u{e5 e1 e2 e4 e3 101 3042}"
|
||||||
|
ENV[key] = "foo"
|
||||||
|
assert_equal(%{{"VAR\u{e5 e1 e2 e4 e3 101 3042}"=>"foo"}}, ENV.inspect)
|
||||||
|
end
|
||||||
|
|
||||||
def test_to_a
|
def test_to_a
|
||||||
ENV.clear
|
ENV.clear
|
||||||
ENV["foo"] = "bar"
|
ENV["foo"] = "bar"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user