From 792d1deb949e8416d7a76d66771b286d35c8278d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 29 Jun 2019 19:07:25 +0900 Subject: [PATCH] Escape control codes in regexp warning message --- regerror.c | 3 ++- test/ruby/test_regexp.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/regerror.c b/regerror.c index 59cf53068e..efcfefffdf 100644 --- a/regerror.c +++ b/regerror.c @@ -356,7 +356,8 @@ onig_vsnprintf_with_pattern(UChar buf[], int bufsize, OnigEncoding enc, *s++ = *p++; } else if (!ONIGENC_IS_CODE_PRINT(enc, *p) && - !ONIGENC_IS_CODE_SPACE(enc, *p)) { + (!ONIGENC_IS_CODE_SPACE(enc, *p) || + ONIGENC_IS_CODE_CNTRL(enc, *p))) { sprint_byte_with_x((char* )bs, (unsigned int )(*p++)); len = onigenc_str_bytelen_null(ONIG_ENCODING_ASCII, bs); bp = bs; diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 18a6d4d7c9..6cfd7df824 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1124,6 +1124,8 @@ class TestRegexp < Test::Unit::TestCase bug8151 = '[ruby-core:53649]' assert_warning(/\A\z/, bug8151) { Regexp.new('(?:[\u{33}])').to_s } + + assert_warning(%r[/.*/\Z]) { Regexp.new("[\n\n]") } end def test_property_warn