mirror of
https://github.com/ruby/ruby.git
synced 2026-08-03 11:18:06 +08:00
Fix coderange of invalid_encoding_string.<<(ord)
Appending valid encoding character can change coderange from invalid to valid.
Example: "\x95".force_encoding('sjis')<<0x5C will be a valid string "\x{955C}"
This commit is contained in:
parent
69cee6fee5
commit
ce372be903
6
string.c
6
string.c
@ -3522,8 +3522,12 @@ rb_str_concat(VALUE str1, VALUE str2)
|
||||
}
|
||||
rb_str_resize(str1, pos+len);
|
||||
memcpy(RSTRING_PTR(str1) + pos, buf, len);
|
||||
if (cr == ENC_CODERANGE_7BIT && code > 127)
|
||||
if (cr == ENC_CODERANGE_7BIT && code > 127) {
|
||||
cr = ENC_CODERANGE_VALID;
|
||||
}
|
||||
else if (cr == ENC_CODERANGE_BROKEN) {
|
||||
cr = ENC_CODERANGE_UNKNOWN;
|
||||
}
|
||||
ENC_CODERANGE_SET(str1, cr);
|
||||
}
|
||||
return str1;
|
||||
|
||||
@ -301,6 +301,9 @@ CODE
|
||||
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << -1}
|
||||
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << 0x81308130}
|
||||
assert_nothing_raised {S("a".force_encoding(Encoding::GB18030)) << 0x81308130}
|
||||
|
||||
s = "\x95".force_encoding(Encoding::SJIS).tap(&:valid_encoding?)
|
||||
assert_predicate(s << 0x5c, :valid_encoding?)
|
||||
end
|
||||
|
||||
def test_MATCH # '=~'
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||
#define RUBY_VERSION_TEENY 0
|
||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||
#define RUBY_PATCHLEVEL 15
|
||||
#define RUBY_PATCHLEVEL 16
|
||||
|
||||
#include "ruby/version.h"
|
||||
#include "ruby/internal/abi.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user