From 54c984a8983c4ca3330d842520f24d3a98675f20 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 4 Jul 2008 23:33:04 +0000 Subject: [PATCH] * re.c (unescape_nonascii): make regexp fixed_encoding if \p is used. fixed [ruby-core:17279]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ re.c | 6 ++++++ test/ruby/test_m17n.rb | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/ChangeLog b/ChangeLog index 88b6f34d60..49835564ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jul 5 08:29:47 2008 Tanaka Akira + + * re.c (unescape_nonascii): make regexp fixed_encoding if \p is used. + fixed [ruby-core:17279]. + Fri Jul 4 23:12:53 2008 Masaki Suketa * ext/win32ole/win32ole.c (d2time): fix the bug of VT_DATE diff --git a/re.c b/re.c index 7734132600..899ede647b 100644 --- a/re.c +++ b/re.c @@ -2163,6 +2163,12 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc, break; } + case 'p': /* \p{Hiragana} */ + if (!*encp) { + *encp = enc; + } + goto escape_asis; + default: /* \n, \\, \d, \9, etc. */ escape_asis: smallbuf[0] = '\\'; diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb index 6f319b2b02..c5871898fe 100644 --- a/test/ruby/test_m17n.rb +++ b/test/ruby/test_m17n.rb @@ -493,6 +493,25 @@ class TestM17N < Test::Unit::TestCase assert_match(/[[:space:]]/, "\u{00a0}") end + def test_regexp_property + s = '\p{Hiragana}'.force_encoding("euc-jp") + assert_equal(Encoding::EUC_JP, s.encoding) + r = nil + assert_nothing_raised { + r = Regexp.new(s) + } + assert(r.fixed_encoding?) + assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) + + r = eval('/\p{Hiragana}/'.force_encoding("euc-jp")) + assert(r.fixed_encoding?) + assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) + + r = /\p{Hiragana}/e + assert(r.fixed_encoding?) + assert_match(r, "\xa4\xa2".force_encoding("euc-jp")) + end + def test_regexp_embed_preprocess r1 = /\xa4\xa2/e r2 = /#{r1}/