Skip to content
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
15 changes: 13 additions & 2 deletions ext/mini_racer_extension/mini_racer_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,24 @@ static VALUE str_encode_bang(VALUE v)

static void des_string8(void *arg, const uint8_t *s, size_t n)
{
rb_encoding *e;
DesCtx *c;
VALUE v;

c = arg;
v = rb_enc_str_new((char *)s, n, rb_ascii8bit_encoding());
if (c->transcode_latin1)
if (*c->err)
return;
if (c->transcode_latin1) {
e = rb_enc_find("ISO-8859-1"); // TODO cache?
if (!e) {
snprintf(c->err, sizeof(c->err), "no ISO-8859-1 encoding");
return;
}
v = rb_enc_str_new((char *)s, n, e);
v = str_encode_bang(v); // cannot fail
} else {
v = rb_enc_str_new((char *)s, n, rb_ascii8bit_encoding());
}
put(c, v);
}

Expand Down
1 change: 1 addition & 0 deletions test/mini_racer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ def test_function_property

def test_string_encoding
context = MiniRacer::Context.new
assert_equal "ä", context.eval("'ä'")
assert_equal "ok", context.eval("'ok'".encode("ISO-8859-1"))
assert_equal "ok", context.eval("'ok'".encode("ISO8859-1"))
assert_equal "ok", context.eval("'ok'".encode("UTF-16LE"))
Expand Down
Loading