зеркало из https://github.com/github/ruby.git
re.c: fixed escaped multibyte char
* re.c (unescape_nonascii): escaped multibyte character should be copied as-is, just with checking if the encoding matches. https://twitter.com/sakuro/status/972014409986883584 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
724878c913
Коммит
5fade63482
12
re.c
12
re.c
|
@ -2537,11 +2537,13 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
|
|||
while (p < end) {
|
||||
int chlen = rb_enc_precise_mbclen(p, end, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(chlen)) {
|
||||
invalid_multibyte:
|
||||
errcpy(err, "invalid multibyte character");
|
||||
return -1;
|
||||
}
|
||||
chlen = MBCLEN_CHARFOUND_LEN(chlen);
|
||||
if (1 < chlen || (*p & 0x80)) {
|
||||
multibyte:
|
||||
rb_str_buf_cat(buf, p, chlen);
|
||||
p += chlen;
|
||||
if (*encp == 0)
|
||||
|
@ -2559,6 +2561,16 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
|
|||
errcpy(err, "too short escape sequence");
|
||||
return -1;
|
||||
}
|
||||
chlen = rb_enc_precise_mbclen(p, end, enc);
|
||||
if (!MBCLEN_CHARFOUND_P(chlen)) {
|
||||
goto invalid_multibyte;
|
||||
}
|
||||
if ((chlen = MBCLEN_CHARFOUND_LEN(chlen)) > 1) {
|
||||
/* include the previous backslash */
|
||||
--p;
|
||||
++chlen;
|
||||
goto multibyte;
|
||||
}
|
||||
switch (c = *p++) {
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6': case '7': /* \O, \OO, \OOO or backref */
|
||||
|
|
|
@ -515,6 +515,8 @@ class TestRegexp < Test::Unit::TestCase
|
|||
s = ".........."
|
||||
5.times { s.sub!(".", "") }
|
||||
assert_equal(".....", s)
|
||||
|
||||
assert_equal("\\\u{3042}", Regexp.new("\\\u{3042}").source)
|
||||
end
|
||||
|
||||
def test_equal
|
||||
|
|
Загрузка…
Ссылка в новой задаче