Skip to content

Set encoding of JS::Object#to_s result string to UTF-8 #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/js/js-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static VALUE _rb_js_obj_to_s(VALUE obj) {
struct jsvalue *p = check_jsvalue(obj);
rb_js_abi_host_string_t ret0;
rb_js_abi_host_js_value_to_string(p->abi, &ret0);
return rb_str_new(ret0.ptr, ret0.len);
return rb_utf8_str_new(ret0.ptr, ret0.len);
}

/*
Expand Down
5 changes: 5 additions & 0 deletions packages/npm-packages/ruby-wasm-wasi/test/unit/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def test_to_s
assert_equal "undefined", JS.eval("return undefined;").to_s
end

def test_to_s_encoding
assert_equal Encoding::UTF_8, JS.eval("return 'str';").to_s.encoding
assert_equal Encoding::UTF_8, JS.eval("return 'あいうえお';").to_s.encoding
end

def test_inspect
assert_equal "str", JS.eval("return 'str';").to_s
assert_equal "24", JS.eval("return 24;").inspect
Expand Down