mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
724878c913
commit
5fade63482
2 changed files with 14 additions and 0 deletions
12
re.c
12
re.c
|
@ -2537,11 +2537,13 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
|
||||||
while (p < end) {
|
while (p < end) {
|
||||||
int chlen = rb_enc_precise_mbclen(p, end, enc);
|
int chlen = rb_enc_precise_mbclen(p, end, enc);
|
||||||
if (!MBCLEN_CHARFOUND_P(chlen)) {
|
if (!MBCLEN_CHARFOUND_P(chlen)) {
|
||||||
|
invalid_multibyte:
|
||||||
errcpy(err, "invalid multibyte character");
|
errcpy(err, "invalid multibyte character");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
chlen = MBCLEN_CHARFOUND_LEN(chlen);
|
chlen = MBCLEN_CHARFOUND_LEN(chlen);
|
||||||
if (1 < chlen || (*p & 0x80)) {
|
if (1 < chlen || (*p & 0x80)) {
|
||||||
|
multibyte:
|
||||||
rb_str_buf_cat(buf, p, chlen);
|
rb_str_buf_cat(buf, p, chlen);
|
||||||
p += chlen;
|
p += chlen;
|
||||||
if (*encp == 0)
|
if (*encp == 0)
|
||||||
|
@ -2559,6 +2561,16 @@ unescape_nonascii(const char *p, const char *end, rb_encoding *enc,
|
||||||
errcpy(err, "too short escape sequence");
|
errcpy(err, "too short escape sequence");
|
||||||
return -1;
|
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++) {
|
switch (c = *p++) {
|
||||||
case '1': case '2': case '3':
|
case '1': case '2': case '3':
|
||||||
case '4': case '5': case '6': case '7': /* \O, \OO, \OOO or backref */
|
case '4': case '5': case '6': case '7': /* \O, \OO, \OOO or backref */
|
||||||
|
|
|
@ -515,6 +515,8 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
s = ".........."
|
s = ".........."
|
||||||
5.times { s.sub!(".", "") }
|
5.times { s.sub!(".", "") }
|
||||||
assert_equal(".....", s)
|
assert_equal(".....", s)
|
||||||
|
|
||||||
|
assert_equal("\\\u{3042}", Regexp.new("\\\u{3042}").source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_equal
|
def test_equal
|
||||||
|
|
Loading…
Add table
Reference in a new issue