Skip to content

Commit

Permalink
Avoid UTF-32 and UTF-16 strings with trailing bytes in mri tests.
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4419
  • Loading branch information
djoooooe committed Dec 4, 2024
2 parents 40f369b + 3e2ab04 commit afce327
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion spec/ruby/core/file/expand_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
platform_is_not :windows do
it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
Encoding.default_external = Encoding::UTF_16BE
-> { File.expand_path("./ab") }.should raise_error(Encoding::CompatibilityError)
-> { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
end
end

Expand Down
15 changes: 9 additions & 6 deletions test/mri/tests/ruby/enc/test_utf16.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def test_utf16be_valid_encoding
}
}
[
"\x00",
"\xd7",
# "\x00", # TruffleString: UTF-16 string byte length is not a multiple of 2
# "\xd7",
"\xd8\x00",
"\xd8\x00\xd8\x00",
"\xdc\x00",
"\xdc\x00\xd8\x00",
"\xdc\x00\xdc\x00",
"\xe0",
"\xff",
# "\xe0",
# "\xff",
].each {|s|
s.force_encoding("utf-16be")
a.for(s) {
Expand Down Expand Up @@ -151,8 +151,11 @@ def test_casecmp
end

def test_end_with
s1 = "ab".force_encoding("utf-16be")
s2 = "b".force_encoding("utf-16be")
# TruffleString: UTF-16 string byte length is not a multiple of 2
# s1 = "ab".force_encoding("utf-16be")
# s2 = "b".force_encoding("utf-16be")
s1 = "\xd8\x00\xdc\x00".force_encoding("utf-16be")
s2 = "\xdc\x00".force_encoding("utf-16be")
assert_equal(false, s1.end_with?(s2), "#{encdump s1}.end_with?(#{encdump s2})")
end

Expand Down
6 changes: 3 additions & 3 deletions test/mri/tests/ruby/enc/test_utf32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def test_utf32be_valid_encoding
}
}
[
"a",
"\x00a",
"\x00\x00a",
# "a", # TruffleString: UTF-32 string byte length is not a multiple of 4
# "\x00a",
# "\x00\x00a",
"\x00\x00\xd8\x00",
"\x00\x00\xdb\xff",
"\x00\x00\xdc\x00",
Expand Down
3 changes: 2 additions & 1 deletion test/mri/tests/ruby/test_m17n_comb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def assert_strenc(bytes, enc, actual, message=nil)
WSTRINGS = [
"aa".force_encoding("utf-16be"),
"aaaa".force_encoding("utf-32be"),
"aaa".force_encoding("utf-32be"),
# TruffleString: UTF-32 string byte length is not a multiple of 4
# "aaa".force_encoding("utf-32be"),
]

def combination(*args, &b)
Expand Down
7 changes: 4 additions & 3 deletions test/mri/tests/ruby/test_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,10 @@ def test_quote
assert_equal("\u3042\\t", Regexp.quote("\u3042\t"))
assert_equal("\\t\xff", Regexp.quote("\t" + [0xff].pack("C")))

bug13034 = '[ruby-core:78646] [Bug #13034]'
str = "\x00".force_encoding("UTF-16BE")
assert_equal(str, Regexp.quote(str), bug13034)
# TruffleString: length of utf-16 string is not a multiple of 2
# bug13034 = '[ruby-core:78646] [Bug #13034]'
# str = "\x00".force_encoding("UTF-16BE")
# assert_equal(str, Regexp.quote(str), bug13034)
end

def test_try_convert
Expand Down
11 changes: 8 additions & 3 deletions test/mri/tests/rubygems/test_gem_safe_marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ class TestGemSafeMarshal < Gem::TestCase
define_method("test_safe_load_marshal Array [\"abc\", \"abc\"] Windows-1256") { assert_safe_load_marshal "\x04\b[\aI\"\babc\x06:\rencoding\"\x11Windows-1256@\x06", additional_methods: [->(x) { x.map(&:encoding) }] }
define_method("test_safe_load_marshal String \"abc\" binary") { assert_safe_load_marshal "\x04\b\"\babc", additional_methods: [:encoding] }
define_method("test_safe_load_marshal Array [\"abc\", \"abc\"] binary") { assert_safe_load_marshal "\x04\b[\a\"\babc@\x06", additional_methods: [->(x) { x.map(&:encoding) }] }
define_method("test_safe_load_marshal String \"\\x61\\x62\\x63\" utf32") { assert_safe_load_marshal "\x04\bI\"\babc\x06:\rencoding\"\vUTF-32", additional_methods: [:encoding] }
define_method("test_safe_load_marshal Array [\"\\x61\\x62\\x63\", \"\\x61\\x62\\x63\"] utf32") { assert_safe_load_marshal "\x04\b[\aI\"\babc\x06:\rencoding\"\vUTF-32@\x06", additional_methods: [->(x) { x.map(&:encoding) }] }
# TruffleString: UTF-32 string byte length is not a multiple of 4
# define_method("test_safe_load_marshal String \"\\x61\\x62\\x63\" utf32") { assert_safe_load_marshal "\x04\bI\"\babc\x06:\rencoding\"\vUTF-32", additional_methods: [:encoding] }
# define_method("test_safe_load_marshal Array [\"\\x61\\x62\\x63\", \"\\x61\\x62\\x63\"] utf32") { assert_safe_load_marshal "\x04\b[\aI\"\babc\x06:\rencoding\"\vUTF-32@\x06", additional_methods: [->(x) { x.map(&:encoding) }] }
define_method("test_safe_load_marshal String \"\\x61\\x62\\x63\\x64\" utf32") { assert_safe_load_marshal "\x04\bI\"\x09abcd\x06:\rencoding\"\vUTF-32", additional_methods: [:encoding] }
define_method("test_safe_load_marshal Array [\"\\x61\\x62\\x63\\x64\", \"\\x61\\x62\\x63\\x64\"] utf32") { assert_safe_load_marshal "\x04\b[\aI\"\x09abcd\x06:\rencoding\"\vUTF-32@\x06", additional_methods: [->(x) { x.map(&:encoding) }] }
define_method("test_safe_load_marshal String \"abc\" ivar") { assert_safe_load_marshal "\x04\bI\"\babc\a:\x06ET:\n@typeI\"\ttype\x06;\x00T", permitted_ivars: { "String" => %w[@type E] } }
define_method("test_safe_load_marshal String \"\"") { assert_safe_load_marshal "\x04\bI\"\babc\x06:\x06ET" }
define_method("test_safe_load_marshal Time 2000-12-31 20:07:59 -1152") { assert_safe_load_marshal "\x04\bIu:\tTime\r'@\x19\x80\x00\x00\xB0\xEF\a:\voffseti\xFE Y:\tzone0", additional_methods: [:ctime, :to_f, :to_r, :to_i, :zone, :subsec, :instance_variables, :dst?, :to_a] }
Expand Down Expand Up @@ -163,7 +166,9 @@ def test_string_with_encoding
String.new("abc", encoding: "UTF-8"),
String.new("abc", encoding: "Windows-1256"),
String.new("abc", encoding: Encoding::BINARY),
String.new("abc", encoding: "UTF-32"),
# TruffleRuby: length of UTF-16 string is not a multiple of 2
# String.new("abc", encoding: "UTF-32"),
String.new("abcd", encoding: "UTF-32"),

String.new("", encoding: "US-ASCII"),
String.new("", encoding: "UTF-8"),
Expand Down

0 comments on commit afce327

Please sign in to comment.