1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]
This commit is contained in:
Jeremy Evans 2020-11-23 11:03:15 -08:00 committed by Benoit Daloze
parent 237cb94cf5
commit b26d6c70e0
Notes: git 2020-11-25 00:02:11 +09:00
2 changed files with 12 additions and 2 deletions

View file

@ -4348,7 +4348,7 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
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)
return r;
}
else if (c == '(' || c == ')' || c == '{' || c == '|') {
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
break;
}
}

View file

@ -57,6 +57,17 @@ class TestRegexp < Test::Unit::TestCase
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")