MRI-Binding: Enforce UTF-8 strings in 'Marshal::load()' via aux proc

We override 'Marshal::load()' via alias and call it with
a custom auxiliary proc in the alias which sets the encoding
of all demarshalled strings to UTF-8. The case where a user
himself provided a proc to 'load()' is not implemented.

This is definitely a better solution than patching the ruby
source tree. Thanks to github.com/cremno for hints and help!
This commit is contained in:
Jonas Kulla 2013-10-20 15:51:24 +02:00
parent e14f3ef9db
commit 27341dc95d
2 changed files with 38 additions and 15 deletions

View file

@ -1,15 +0,0 @@
diff --git a/marshal.c b/marshal.c
index 4cba05d..dfce6ee 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1312,7 +1312,9 @@ r_unique(struct load_arg *arg)
static VALUE
r_string(struct load_arg *arg)
{
- return r_bytes(arg);
+ VALUE str = r_bytes(arg);
+ rb_enc_associate(str, rb_utf8_encoding());
+ return str;
}
static VALUE