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:
parent
237cb94cf5
commit
b26d6c70e0
Notes:
git
2020-11-25 00:02:11 +09:00
2 changed files with 12 additions and 2 deletions
|
@ -4348,7 +4348,7 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
|
||||||
OnigEncoding enc = env->enc;
|
OnigEncoding enc = env->enc;
|
||||||
UChar *prev, *start, *p = *src;
|
UChar *prev, *start, *p = *src;
|
||||||
|
|
||||||
r = 0;
|
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
||||||
start = prev = p;
|
start = prev = p;
|
||||||
|
|
||||||
while (!PEND) {
|
while (!PEND) {
|
||||||
|
@ -4362,7 +4362,6 @@ fetch_char_property_to_ctype(UChar** src, UChar* end, ScanEnv* env)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
else if (c == '(' || c == ')' || c == '{' || c == '|') {
|
else if (c == '(' || c == ')' || c == '{' || c == '|') {
|
||||||
r = ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,17 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
assert_equal('Ruby', 'Ruby'.sub(/[^a-z]/i, '-'))
|
assert_equal('Ruby', 'Ruby'.sub(/[^a-z]/i, '-'))
|
||||||
end
|
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
|
def test_assert_normal_exit
|
||||||
# moved from knownbug. It caused core.
|
# moved from knownbug. It caused core.
|
||||||
Regexp.union("a", "a")
|
Regexp.union("a", "a")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue