[前][次][番号順一覧][スレッド一覧]

ruby-changes:63739

From: Jeremy <ko1@a...>
Date: Wed, 25 Nov 2020 00:02:00 +0900 (JST)
Subject: [ruby-changes:63739] b26d6c70e0 (master): Detect the premature end of char property in regexp

https://git.ruby-lang.org/ruby.git/commit/?id=b26d6c70e0

From b26d6c70e0f08050ca23388bb0e8442f73269c73 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Mon, 23 Nov 2020 11:03:15 -0800
Subject: Detect the premature end of char property in regexp

Default to ONIGERR_INVALID_CHAR_PROPERTY_NAME in
fetch_char_property_to_ctype and only set otherwise if an ending
} is found.

Fixes [Bug #17340]

diff --git a/regparse.c b/regparse.c
index a96c8c2..7639db3 100644
--- a/regparse.c
+++ b/regparse.c
@@ -4348,7 +4348,7 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env) https://github.com/ruby/ruby/blob/trunk/regparse.c#L4348
   OnigEncoding enc = env->enc;
   UChar *prev, *start, *p = *src;
 
-  r = 0;
+  r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
   start = prev = p;
 
   while (!PEND) {
@@ -4362,7 +4362,6 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env) https://github.com/ruby/ruby/blob/trunk/regparse.c#L4362
       return r;
     }
     else if (c == '(' || c == ')' || c == '{' || c == '|') {
-      r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
       break;
     }
   }
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 231fd39..220e2b7 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -57,6 +57,17 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L57
     assert_equal('Ruby', 'Ruby'.sub(/[^a-z]/i, '-'))
   end
 
+  def test_premature_end_char_property
+    ["\\p{",
+     "\\p{".dup.force_encoding("UTF-8"),
+     "\\p{".dup.force_encoding("US-ASCII")
+    ].each do |string|
+      assert_raise(RegexpError) do
+        Regexp.new(string)
+      end
+    end
+  end
+
   def test_assert_normal_exit
     # moved from knownbug.  It caused core.
     Regexp.union("a", "a")
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]