aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y22
-rw-r--r--test/ruby/test_m17n.rb8
3 files changed, 32 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index cce0ff4ccd..5bc9e4bbe9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Dec 2 09:12:48 2007 Tanaka Akira <akr@fsij.org>
+
+ * parse.y (regexp): fix /#{}\xa1\xa2/e to be EUC-JP.
+ (reg_fragment_setenc_gen): extracted from reg_compile_gen.
+
Sun Dec 2 01:39:51 2007 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h (rb_uv_to_utf8): declared.
diff --git a/parse.y b/parse.y
index 264a3d2d63..2bfd9e09b0 100644
--- a/parse.y
+++ b/parse.y
@@ -442,6 +442,8 @@ extern int rb_parse_in_eval(void);
static VALUE reg_compile_gen(struct parser_params*, VALUE, int);
#define reg_compile(str,options) reg_compile_gen(parser, str, options)
+static void reg_fragment_setenc_gen(struct parser_params*, VALUE, int);
+#define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, str, options)
#else
#define remove_begin(node) (node)
#endif /* !RIPPER */
@@ -3642,6 +3644,7 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
/*%%%*/
int options = $3;
NODE *node = $2;
+ NODE *list;
if (!node) {
node = NEW_LIT(reg_compile(STR_NEW0(), options));
}
@@ -3663,6 +3666,12 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END
nd_set_type(node, NODE_DREGX);
}
node->nd_cflag = options & RE_OPTION_MASK;
+ reg_fragment_setenc(node->nd_lit, options);
+ for (list = node->nd_next; list; list = list->nd_next) {
+ if (nd_type(list->nd_head) == NODE_STR) {
+ reg_fragment_setenc(list->nd_head->nd_lit, options);
+ }
+ }
break;
}
$$ = node;
@@ -8436,10 +8445,9 @@ dvar_curr_gen(struct parser_params *parser, ID id)
VALUE rb_reg_compile(VALUE str, int options);
-static VALUE
-reg_compile_gen(struct parser_params* parser, VALUE str, int options)
+static void
+reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options)
{
- VALUE re;
int c = RE_OPTION_ENCODING_IDX(options);
if (c) {
@@ -8453,6 +8461,14 @@ reg_compile_gen(struct parser_params* parser, VALUE str, int options)
}
ENCODING_SET(str, idx);
}
+}
+
+static VALUE
+reg_compile_gen(struct parser_params* parser, VALUE str, int options)
+{
+ VALUE re;
+
+ reg_fragment_setenc(str, options);
re = rb_reg_compile(str, options & RE_OPTION_MASK);
if (NIL_P(re)) {
RB_GC_GUARD(re) = rb_obj_as_string(rb_errinfo());
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index bb0a8a5010..8f763e029a 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -301,4 +301,12 @@ class TestM17N < Test::Unit::TestCase
}
}
end
+
+ def test_dynamic_euc_regexp
+ assert_encoding("EUC-JP", /#{}\xc0\xa1/e.encoding)
+ assert_raise(RegexpError) { eval('/\xa1#{}/e') }
+ assert_raise(RegexpError) { eval('/#{}\xa1/e') }
+ #assert_raise(SyntaxError) { eval('/\xa1#{}\xa1/e') }
+ #assert_raise(SyntaxError) { s = e('\xa1'); /#{s}#{s}/ }
+ end
end