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

* re.c (append_utf8): check unicode range.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-12-09 03:50:11 +00:00
parent 78cc1c45ee
commit 5a1c2b2677
3 changed files with 27 additions and 4 deletions

View file

@ -1,3 +1,7 @@
Sun Dec 9 12:49:34 2007 Tanaka Akira <akr@fsij.org>
* re.c (append_utf8): check unicode range.
Sun Dec 9 12:39:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/cgi.rb (read_multipart): exclude blanks from header values.

17
re.c
View file

@ -1424,10 +1424,23 @@ unescape_escaped_nonascii(const char **pp, const char *end, rb_encoding *enc,
return 0;
}
static int
check_unicode_range(unsigned long code, onig_errmsg_buffer err)
{
if ((0xd800 <= code && code <= 0xdfff) || /* Surrogates */
0x10ffff < code) {
strcpy(err, "invalid Unicode range");
return -1;
}
return 0;
}
static int
append_utf8(unsigned long uv,
VALUE buf, rb_encoding **encp, onig_errmsg_buffer err)
{
if (check_unicode_range(uv, err) != 0)
return -1;
if (uv < 0x80) {
char escbuf[5];
snprintf(escbuf, sizeof(escbuf), "\\x%02x", (int)uv);
@ -1468,10 +1481,6 @@ unescape_unicode_list(const char **pp, const char *end,
strcpy(err, "invalid Unicode range");
return -1;
}
if (0x10ffff < code) {
strcpy(err, "invalid Unicode range");
return -1;
}
p += len;
if (append_utf8(code, buf, encp, err) != 0)
return -1;

View file

@ -446,6 +446,16 @@ class TestM17N < Test::Unit::TestCase
#assert_raise(SyntaxError) { s1, s2 = u('\xc2'), u('\xa1'); /#{s1}#{s2}/ }
end
def test_regexp_unicode
assert_nothing_raised { eval '/\u{0}/' }
assert_nothing_raised { eval '/\u{D7FF}/' }
assert_raise(SyntaxError) { eval '/\u{D800}/' }
assert_raise(SyntaxError) { eval '/\u{DFFF}/' }
assert_nothing_raised { eval '/\u{E000}/' }
assert_nothing_raised { eval '/\u{10FFFF}/' }
assert_raise(SyntaxError) { eval '/\u{110000}/' }
end
def test_regexp_mixed_unicode
assert_raise(SyntaxError) { eval(a(%{/\xc2\xa0\\u{6666}/})) }
assert_raise(SyntaxError) { eval(e(%{/\xc2\xa0\\u{6666}/})) }