Skip to content

Commit be09d77

Browse files
committed
merge revision(s) a8ba1dd: [Backport #19455]
Use UTF-8 encoding for literal extended regexps with UTF-8 characters in comments Fixes [Bug #19455] --- re.c | 9 ++++++++- test/ruby/test_regexp.rb | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
1 parent 5fbd727 commit be09d77

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

re.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,11 @@ unescape_nonascii0(const char **pp, const char *end, rb_encoding *enc,
29262926
case '#':
29272927
if (extended_mode && !in_char_class) {
29282928
/* consume and ignore comment in extended regexp */
2929-
while ((p < end) && ((c = *p++) != '\n'));
2929+
while ((p < end) && ((c = *p++) != '\n')) {
2930+
if ((c & 0x80) && !*encp && enc == rb_utf8_encoding()) {
2931+
*encp = enc;
2932+
}
2933+
}
29302934
break;
29312935
}
29322936
rb_str_buf_cat(buf, (char *)&c, 1);
@@ -2961,6 +2965,9 @@ unescape_nonascii0(const char **pp, const char *end, rb_encoding *enc,
29612965
switch (c = *p++) {
29622966
default:
29632967
if (!(c & 0x80)) break;
2968+
if (!*encp && enc == rb_utf8_encoding()) {
2969+
*encp = enc;
2970+
}
29642971
--p;
29652972
/* fallthrough */
29662973
case '\\':

test/ruby/test_regexp.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ def test_nonextended_section_of_extended_regexp_bug_19379
200200
RUBY
201201
end
202202

203+
def test_utf8_comment_in_usascii_extended_regexp_bug_19455
204+
assert_separately([], <<-RUBY)
205+
assert_equal(Encoding::UTF_8, /(?#\u1000)/x.encoding)
206+
assert_equal(Encoding::UTF_8, /#\u1000/x.encoding)
207+
RUBY
208+
end
209+
203210
def test_union
204211
assert_equal :ok, begin
205212
Regexp.union(

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 2
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 90
14+
#define RUBY_PATCHLEVEL 91
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)