Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 770060f

Browse files
committed
merge revision(s) 1acfb29: [Backport #21186]
[Bug #21186] multibyte char literal should be a single letter word
1 parent d2eda78 commit 770060f

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

parse.y

+6-7
Original file line numberDiff line numberDiff line change
@@ -9884,6 +9884,7 @@ parse_qmark(struct parser_params *p, int space_seen)
98849884
rb_encoding *enc;
98859885
register int c;
98869886
VALUE lit;
9887+
const char *start = p->lex.pcur;
98879888

98889889
if (IS_END()) {
98899890
SET_LEX_STATE(EXPR_VALUE);
@@ -9908,13 +9909,11 @@ parse_qmark(struct parser_params *p, int space_seen)
99089909
}
99099910
newtok(p);
99109911
enc = p->enc;
9911-
if (!parser_isascii(p)) {
9912-
if (tokadd_mbchar(p, c) == -1) return 0;
9913-
}
9914-
else if ((rb_enc_isalnum(c, p->enc) || c == '_') &&
9915-
!lex_eol_p(p) && is_identchar(p, p->lex.pcur, p->lex.pend, p->enc)) {
9912+
int w = parser_precise_mbclen(p, start);
9913+
if (is_identchar(p, start, p->lex.pend, p->enc) &&
9914+
!(lex_eol_ptr_n_p(p, start, w) || !is_identchar(p, start + w, p->lex.pend, p->enc))) {
99169915
if (space_seen) {
9917-
const char *start = p->lex.pcur - 1, *ptr = start;
9916+
const char *ptr = start;
99189917
do {
99199918
int n = parser_precise_mbclen(p, ptr);
99209919
if (n < 0) return -1;
@@ -9942,7 +9941,7 @@ parse_qmark(struct parser_params *p, int space_seen)
99429941
}
99439942
}
99449943
else {
9945-
tokadd(p, c);
9944+
if (tokadd_mbchar(p, c) == -1) return 0;
99469945
}
99479946
tokfix(p);
99489947
lit = STR_NEW3(tok(p), toklen(p), enc, 0);

test/ruby/test_parse.rb

+2
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ def test_question
631631
assert_equal("\u{1234}", eval('?\u{1234}'))
632632
assert_equal("\u{1234}", eval('?\u1234'))
633633
assert_syntax_error('?\u{41 42}', 'Multiple codepoints at single character literal')
634+
assert_syntax_error("?and", /unexpected '\?'/)
635+
assert_syntax_error("?\u1234and", /unexpected '\?'/)
634636
e = assert_syntax_error('"#{?\u123}"', 'invalid Unicode escape')
635637
assert_not_match(/end-of-input/, e.message)
636638

version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 136
14+
#define RUBY_PATCHLEVEL 137
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)