summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--ext/strscan/strscan.c2
-rw-r--r--intern.h2
-rw-r--r--re.c34
-rw-r--r--test/strscan/test_stringscanner.rb13
5 files changed, 46 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index a98a39f57a..708d1c9ad1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Wed Jan 10 18:57:57 2007 Minero Aoki <aamine@loveruby.net>
+
+ * ext/strscan/strscan.c (strscan_do_scan): should set kcode option
+ before match. [ruby-dev:29914]
+
+ * test/strscan/test_stringscanner.rb: test it.
+
+ * re.c: export kcode_set_option and kcode_reset_option (with "rb_"
+ prefix).
+
+ * intern.h: ditto.
+
Tue Jan 9 17:45:17 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* file.c (rb_find_file): should not call fpath_check() with NULL.
diff --git a/ext/strscan/strscan.c b/ext/strscan/strscan.c
index fdbfc79919..b5ee20282c 100644
--- a/ext/strscan/strscan.c
+++ b/ext/strscan/strscan.c
@@ -403,6 +403,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
if (S_RESTLEN(p) < 0) {
return Qnil;
}
+ rb_kcode_set_option(regex);
if (headonly) {
ret = re_match(RREGEXP(regex)->ptr,
CURPTR(p), S_RESTLEN(p),
@@ -416,6 +417,7 @@ strscan_do_scan(VALUE self, VALUE regex, int succptr, int getstr, int headonly)
S_RESTLEN(p),
&(p->regs));
}
+ rb_kcode_reset_option();
if (ret == -2) rb_raise(ScanError, "regexp buffer overflow");
if (ret < 0) {
diff --git a/intern.h b/intern.h
index 13754b60b1..1fa6da3327 100644
--- a/intern.h
+++ b/intern.h
@@ -370,6 +370,8 @@ VALUE rb_reg_match2 _((VALUE));
int rb_reg_options _((VALUE));
void rb_set_kcode _((const char*));
const char* rb_get_kcode _((void));
+void rb_kcode_set_option _((VALUE));
+void rb_kcode_reset_option _((void));
/* ruby.c */
RUBY_EXTERN VALUE rb_argv;
RUBY_EXTERN VALUE rb_argv0;
diff --git a/re.c b/re.c
index d3de8f92e2..446ea4fa24 100644
--- a/re.c
+++ b/re.c
@@ -200,8 +200,8 @@ kcode_none(re)
static int curr_kcode;
-static void
-kcode_set_option(re)
+void
+rb_kcode_set_option(re)
VALUE re;
{
if (!FL_TEST(re, KCODE_FIXED)) return;
@@ -224,8 +224,8 @@ kcode_set_option(re)
}
}
-static void
-kcode_reset_option()
+void
+rb_kcode_reset_option()
{
if (reg_kcode == curr_kcode) return;
switch (reg_kcode) {
@@ -253,9 +253,9 @@ rb_reg_mbclen2(c, re)
if (!FL_TEST(re, KCODE_FIXED))
return mbclen(c);
- kcode_set_option(re);
+ rb_kcode_set_option(re);
len = mbclen(c);
- kcode_reset_option();
+ rb_kcode_reset_option();
return len;
}
@@ -486,11 +486,11 @@ rb_reg_to_s(re)
}
if (*ptr == ':' && ptr[len-1] == ')') {
Regexp *rp;
- kcode_set_option(re);
+ rb_kcode_set_option(re);
rp = ALLOC(Regexp);
MEMZERO((char *)rp, Regexp, 1);
err = re_compile_pattern(++ptr, len -= 2, rp) != 0;
- kcode_reset_option();
+ rb_kcode_reset_option();
re_free_pattern(rp);
}
if (err) {
@@ -849,7 +849,7 @@ rb_reg_prepare_re(re)
char *err;
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
rb_reg_check(re);
RREGEXP(re)->ptr->fastmap_accurate = 0;
err = re_compile_pattern(RREGEXP(re)->str, RREGEXP(re)->len, RREGEXP(re)->ptr);
@@ -870,9 +870,9 @@ rb_reg_adjust_startpos(re, str, pos, reverse)
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
- kcode_reset_option();
+ rb_kcode_reset_option();
if (reverse) {
range = -pos;
@@ -904,9 +904,9 @@ rb_reg_search(re, str, pos, reverse)
if (may_need_recompile) rb_reg_prepare_re(re);
if (FL_TEST(re, KCODE_FIXED))
- kcode_set_option(re);
+ rb_kcode_set_option(re);
else if (reg_kcode != curr_kcode)
- kcode_reset_option();
+ rb_kcode_reset_option();
if (reverse) {
range = -pos;
@@ -918,7 +918,7 @@ rb_reg_search(re, str, pos, reverse)
pos, range, &regs);
if (FL_TEST(re, KCODE_FIXED))
- kcode_reset_option();
+ rb_kcode_reset_option();
if (result == -2) {
rb_reg_raise(RREGEXP(re)->str, RREGEXP(re)->len,
@@ -1364,7 +1364,7 @@ rb_reg_initialize(obj, s, len, options)
}
if (options & ~0xf) {
- kcode_set_option((VALUE)re);
+ rb_kcode_set_option((VALUE)re);
}
if (ruby_ignorecase) {
options |= RE_OPTION_IGNORECASE;
@@ -1376,7 +1376,7 @@ rb_reg_initialize(obj, s, len, options)
re->str[len] = '\0';
re->len = len;
if (options & ~0xf) {
- kcode_reset_option();
+ rb_kcode_reset_option();
}
if (ruby_in_compile) FL_SET(obj, REG_LITERAL);
}
@@ -1839,7 +1839,7 @@ rb_reg_s_quote(argc, argv)
}
StringValue(str);
str = rb_reg_quote(str);
- kcode_reset_option();
+ rb_kcode_reset_option();
return str;
}
diff --git a/test/strscan/test_stringscanner.rb b/test/strscan/test_stringscanner.rb
index 5b0fd53c75..75e96c0293 100644
--- a/test/strscan/test_stringscanner.rb
+++ b/test/strscan/test_stringscanner.rb
@@ -247,6 +247,19 @@ class TestStringScanner < Test::Unit::TestCase
s = StringScanner.new("")
assert_equal "", s.scan(//)
assert_equal "", s.scan(//)
+
+ # [ruby-dev:29914]
+ %w( NONE EUC SJIS UTF8 ).each do |kcode|
+ begin
+ $KCODE = kcode
+ assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/n)
+ assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/e)
+ assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/s)
+ assert_equal "a", StringScanner.new("a:b").scan(/[^\x01\:]+/u)
+ ensure
+ $KCODE = 'NONE'
+ end
+ end
end
def test_skip