mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (rb_reg_preprocess_dregexp): use non-preprocessed regexp source
for result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8435c6bb8c
commit
ec4756f633
3 changed files with 25 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Feb 14 12:30:02 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* re.c (rb_reg_preprocess_dregexp): use non-preprocessed regexp source
|
||||
for result.
|
||||
|
||||
Thu Feb 14 01:43:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/timeout.rb (Timeout::timeout): made sensitive to location on the
|
||||
|
|
25
re.c
25
re.c
|
@ -1953,6 +1953,7 @@ static VALUE
|
|||
rb_reg_preprocess_dregexp(VALUE ary)
|
||||
{
|
||||
rb_encoding *fixed_enc = 0;
|
||||
rb_encoding *regexp_enc = 0;
|
||||
onig_errmsg_buffer err = "";
|
||||
int i;
|
||||
VALUE result = 0;
|
||||
|
@ -1967,31 +1968,33 @@ rb_reg_preprocess_dregexp(VALUE ary)
|
|||
VALUE str = argv[i];
|
||||
VALUE buf;
|
||||
char *p, *end;
|
||||
rb_encoding *enc;
|
||||
rb_encoding *src_enc;
|
||||
|
||||
StringValue(str);
|
||||
p = RSTRING_PTR(str);
|
||||
end = p + RSTRING_LEN(str);
|
||||
enc = rb_enc_get(str);
|
||||
src_enc = rb_enc_get(str);
|
||||
|
||||
buf = rb_reg_preprocess(p, end, enc, &fixed_enc, err);
|
||||
RB_GC_GUARD(str);
|
||||
buf = rb_reg_preprocess(p, end, src_enc, &fixed_enc, err);
|
||||
|
||||
if (buf == Qnil)
|
||||
rb_raise(rb_eArgError, "%s", err);
|
||||
|
||||
if (i == 0) {
|
||||
/* The encoding of the first fragment is the encoding
|
||||
* given by the regexp option or script encoding. */
|
||||
if (fixed_enc == 0) {
|
||||
rb_enc_copy(buf, str);
|
||||
if (fixed_enc != 0) {
|
||||
if (regexp_enc != 0 && regexp_enc != fixed_enc) {
|
||||
rb_raise(rb_eArgError, "encoding mismatch in dynamic regexp : %s and %s",
|
||||
rb_enc_name(regexp_enc), rb_enc_name(fixed_enc));
|
||||
}
|
||||
regexp_enc = fixed_enc;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
result = buf;
|
||||
result = rb_str_new3(str);
|
||||
else
|
||||
rb_str_buf_append(result, buf);
|
||||
rb_str_buf_append(result, str);
|
||||
}
|
||||
if (regexp_enc) {
|
||||
rb_enc_associate(result, regexp_enc);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -452,6 +452,12 @@ class TestM17N < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError) { /\xc2\xa1#{r}/s }
|
||||
end
|
||||
|
||||
def test_regexp_embed_preprocess
|
||||
r1 = /\xa4\xa2/e
|
||||
r2 = /#{r1}/
|
||||
assert(r2.source.include?(r1.source))
|
||||
end
|
||||
|
||||
def test_begin_end_offset
|
||||
str = e("\244\242\244\244\244\246\244\250\244\252a")
|
||||
assert(/(a)/ =~ str)
|
||||
|
|
Loading…
Reference in a new issue