mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* re.c (rb_reg_to_s): convert closing parenthes to the target encoding
if it is ASCII incompatible encoding. [ruby-core:56063] [Bug #8650] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6c00e17706
commit
6be6666fba
3 changed files with 37 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Jul 25 17:49:42 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* re.c (rb_reg_to_s): convert closing parenthes to the target encoding
|
||||||
|
if it is ASCII incompatible encoding. [ruby-core:56063] [Bug #8650]
|
||||||
|
|
||||||
Thu Jul 25 17:21:21 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Jul 25 17:21:21 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* encoding.c (is_obj_encoding): new macro to check if obj is an
|
* encoding.c (is_obj_encoding): new macro to check if obj is an
|
||||||
|
|
22
re.c
22
re.c
|
@ -597,8 +597,30 @@ rb_reg_to_s(VALUE re)
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_str_buf_cat2(str, ":");
|
rb_str_buf_cat2(str, ":");
|
||||||
|
if (rb_enc_asciicompat(enc)) {
|
||||||
rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
|
rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
|
||||||
rb_str_buf_cat2(str, ")");
|
rb_str_buf_cat2(str, ")");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const char *s, *e;
|
||||||
|
char *paren;
|
||||||
|
ptrdiff_t n;
|
||||||
|
rb_str_buf_cat2(str, ")");
|
||||||
|
rb_enc_associate(str, rb_usascii_encoding());
|
||||||
|
str = rb_str_encode(str, rb_enc_from_encoding(enc), 0, Qnil);
|
||||||
|
|
||||||
|
/* backup encoded ")" to paren */
|
||||||
|
s = RSTRING_PTR(str);
|
||||||
|
e = RSTRING_END(str);
|
||||||
|
s = rb_enc_left_char_head(s, e-1, e, enc);
|
||||||
|
n = e - s;
|
||||||
|
paren = ALLOCA_N(char, n);
|
||||||
|
memcpy(paren, s, n);
|
||||||
|
rb_str_resize(str, RSTRING_LEN(str) - n);
|
||||||
|
|
||||||
|
rb_reg_expr_str(str, (char*)ptr, len, enc, NULL);
|
||||||
|
rb_str_buf_cat(str, paren, n);
|
||||||
|
}
|
||||||
rb_enc_copy(str, re);
|
rb_enc_copy(str, re);
|
||||||
|
|
||||||
OBJ_INFECT(str, re);
|
OBJ_INFECT(str, re);
|
||||||
|
|
|
@ -64,6 +64,14 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_to_s
|
def test_to_s
|
||||||
assert_equal '(?-mix:\x00)', Regexp.new("\0").to_s
|
assert_equal '(?-mix:\x00)', Regexp.new("\0").to_s
|
||||||
|
|
||||||
|
str = "abcd\u3042"
|
||||||
|
[:UTF_16BE, :UTF_16LE, :UTF_32BE, :UTF_32LE].each do |es|
|
||||||
|
enc = Encoding.const_get(es)
|
||||||
|
rs = Regexp.new(str.encode(enc)).to_s
|
||||||
|
assert_equal("(?-mix:abcd\u3042)".encode(enc), rs)
|
||||||
|
assert_equal(enc, rs.encoding)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_union
|
def test_union
|
||||||
|
|
Loading…
Add table
Reference in a new issue