diff --git a/ChangeLog b/ChangeLog index 1887f0e068..016111311c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Dec 14 00:54:40 2007 Yukihiro Matsumoto + + * re.c (rb_reg_initialize): embedded string may override encoding + of the regular expression. + + * re.c (rb_reg_initialize): fix encoding of regular expression if + embedded string has its own encoding specified. + Thu Dec 13 22:16:46 2007 Yukihiro Matsumoto * encoding.c (rb_enc_compatible): encoding should never fall back diff --git a/re.c b/re.c index 330590ea99..4559d02be5 100644 --- a/re.c +++ b/re.c @@ -1954,6 +1954,7 @@ rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc, struct RRegexp *re = RREGEXP(obj); VALUE unescaped; rb_encoding *fixed_enc = 0; + rb_encoding *d_enc = rb_default_encoding(); if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify regexp"); @@ -1969,15 +1970,19 @@ rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc, if (unescaped == Qnil) return -1; - if (fixed_enc && fixed_enc != enc) { - strcpy(err, "character encodings differ"); - return -1; + if (fixed_enc) { + if (fixed_enc != enc && enc != d_enc && fixed_enc != d_enc) { + strcpy(err, "character encodings differ"); + return -1; + } + if (fixed_enc != d_enc) { + options |= ARG_ENCODING_FIXED; + enc = fixed_enc; + } + } + else if (!(options & ARG_ENCODING_FIXED)) { + enc = d_enc; } - - if (fixed_enc) - enc = fixed_enc; - else if (!(options & ARG_ENCODING_FIXED)) - enc = rb_default_encoding(); rb_enc_associate((VALUE)re, enc); if ((options & ARG_ENCODING_FIXED) || fixed_enc) { diff --git a/version.h b/version.h index 027c64de08..daf268fedc 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-12-13" +#define RUBY_RELEASE_DATE "2007-12-14" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20071213 +#define RUBY_RELEASE_CODE 20071214 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 13 +#define RUBY_RELEASE_DAY 14 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[];