зеркало из https://github.com/github/ruby.git
* marshal.c (has_encoding): added for check the regexp
is dumped by 1.8 or 1.9. * marshal.c (r_object0): use has_encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
334241e3ed
Коммит
8ab0220352
|
@ -1,3 +1,10 @@
|
|||
Mon Oct 12 03:47:42 2009 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* marshal.c (has_encoding): added for check the regexp
|
||||
is dumped by 1.8 or 1.9.
|
||||
|
||||
* marshal.c (r_object0): use has_encoding.
|
||||
|
||||
Sun Oct 11 15:54:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/gdbm/gdbm.c (fgdbm_select): fixed rdoc. a patch from Justin
|
||||
|
|
53
marshal.c
53
marshal.c
|
@ -1304,6 +1304,35 @@ obj_alloc_by_path(VALUE path, struct load_arg *arg)
|
|||
|
||||
#define div0(x) ruby_div0(x)
|
||||
|
||||
static int
|
||||
has_encoding(struct load_arg *arg)
|
||||
{
|
||||
int res = FALSE;
|
||||
long offset = arg->offset;
|
||||
r_long(arg);
|
||||
switch (r_byte(arg)) {
|
||||
case ':':
|
||||
switch (r_byte(arg)) {
|
||||
case 6:
|
||||
if (r_byte(arg) == 'E') res = TRUE;
|
||||
break;
|
||||
case 13:
|
||||
if (r_byte(arg) == 'e') res = TRUE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ';':
|
||||
{
|
||||
ID id = r_symlink(arg);
|
||||
if (id == rb_intern("E") || id == rb_id_encoding())
|
||||
res = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
arg->offset = offset;
|
||||
return res;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
||||
{
|
||||
|
@ -1474,21 +1503,17 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
{
|
||||
volatile VALUE str = r_bytes(arg);
|
||||
int options = r_byte(arg);
|
||||
VALUE args[2];
|
||||
args[0] = str;
|
||||
args[1] = INT2FIX(options);
|
||||
v = r_entry(rb_obj_alloc(rb_cRegexp), arg);
|
||||
if (ivp) {
|
||||
r_ivar(v, arg);
|
||||
*ivp = FALSE;
|
||||
|
||||
if (!ivp || !has_encoding(arg)) {
|
||||
VALUE pat;
|
||||
VALUE dst;
|
||||
char *rsrc =
|
||||
"(?<!\\\\)((?:\\\\\\\\)*)\\\\([ghijklmopquyEFHIJKLNOPQRSTUVXY])";
|
||||
pat = rb_reg_new(rsrc, strlen(rsrc), 0);
|
||||
dst = rb_usascii_str_new_cstr("\\1\\2");
|
||||
rb_funcall(str, rb_intern("gsub!"), 2, pat, dst);
|
||||
}
|
||||
if (rb_enc_get_index(v) != rb_usascii_encindex())
|
||||
rb_enc_copy(str, v);
|
||||
if (rb_enc_get_index(str) != rb_utf8_encindex()) {
|
||||
#define f_gsub_bang(x,y,z) rb_funcall(x, rb_intern("gsub!"), 2, y, z)
|
||||
f_gsub_bang(str, rb_reg_new("\\\\u", 3, 0), rb_usascii_str_new_cstr("u"));
|
||||
}
|
||||
rb_obj_call_init(v, 2, args);
|
||||
v = r_entry(rb_reg_new_str(str, options), arg);
|
||||
v = r_leave(v, arg);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -206,11 +206,15 @@ class TestMarshal < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_regexp
|
||||
assert_equal(/\\u/, Marshal.load("\004\b/\b\\\\u\000"))
|
||||
assert_equal(/u/, Marshal.load("\004\b/\a\\u\000"))
|
||||
assert_equal(/u/, Marshal.load("\004\bI/\a\\u\000\006:\016@encoding\"\vEUC-JP"))
|
||||
|
||||
bug2109 = '[ruby-core:25625]'
|
||||
a = "\x82\xa0".force_encoding(Encoding::Windows_31J)
|
||||
b = "\x82\xa2".force_encoding(Encoding::Windows_31J)
|
||||
c = [/#{a}/, /#{b}/]
|
||||
assert_equal(c, Marshal.load(Marshal.dump(c)))
|
||||
assert_equal(c, Marshal.load(Marshal.dump(c)), bug2109)
|
||||
end
|
||||
|
||||
class DumpTest
|
||||
|
|
Загрузка…
Ссылка в новой задаче