Skip to content

Commit ce372be

Browse files
authored
merge revision(s) ade5673: [Backport #20190] (ruby#10300)
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}"
1 parent 69cee6f commit ce372be

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

string.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3522,8 +3522,12 @@ rb_str_concat(VALUE str1, VALUE str2)
35223522
}
35233523
rb_str_resize(str1, pos+len);
35243524
memcpy(RSTRING_PTR(str1) + pos, buf, len);
3525-
if (cr == ENC_CODERANGE_7BIT && code > 127)
3525+
if (cr == ENC_CODERANGE_7BIT && code > 127) {
35263526
cr = ENC_CODERANGE_VALID;
3527+
}
3528+
else if (cr == ENC_CODERANGE_BROKEN) {
3529+
cr = ENC_CODERANGE_UNKNOWN;
3530+
}
35273531
ENC_CODERANGE_SET(str1, cr);
35283532
}
35293533
return str1;

test/ruby/test_string.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def test_LSHIFT # '<<'
301301
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << -1}
302302
assert_raise(RangeError, bug) {S("a".force_encoding(Encoding::UTF_8)) << 0x81308130}
303303
assert_nothing_raised {S("a".force_encoding(Encoding::GB18030)) << 0x81308130}
304+
305+
s = "\x95".force_encoding(Encoding::SJIS).tap(&:valid_encoding?)
306+
assert_predicate(s << 0x5c, :valid_encoding?)
304307
end
305308

306309
def test_MATCH # '=~'

version.h

Lines changed: 1 addition & 1 deletion
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 0
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 15
14+
#define RUBY_PATCHLEVEL 16
1515

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy