diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-02-09 13:50:36 -0800 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-02-20 11:17:47 +0900 |
commit | cfd162d535c7a4f8b1f95255cc6be696a8b75557 (patch) | |
tree | 386d466aab972781cc6d1e35abd035bea506b65d /test | |
parent | efd19badf43f4f1f24d5aec8a28e94a6e1e47b5b (diff) |
Make String#{strip,lstrip}{,!} strip leading NUL bytes
The documentation already specifies that they strip whitespace
and defines whitespace to include null.
This wraps the new behavior in the appropriate guards in the specs,
but does not specify behavior for previous versions, because this
is a bug that could be backported.
Fixes [Bug #17467]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4164
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_string.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4814872789..29ad98beaf 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -1852,6 +1852,7 @@ CODE def test_strip assert_equal(S("x"), S(" x ").strip) assert_equal(S("x"), S(" \n\r\t x \t\r\n\n ").strip) + assert_equal(S("x"), S("\x00x\x00").strip) assert_equal("0b0 ".force_encoding("UTF-16BE"), "\x00 0b0 ".force_encoding("UTF-16BE").strip) @@ -1870,6 +1871,10 @@ CODE assert_equal(S("x"), a.strip!) assert_equal(S("x"), a) + a = S("\x00x\x00") + assert_equal(S("x"), a.strip!) + assert_equal(S("x"), a) + a = S("x") assert_nil(a.strip!) assert_equal(S("x") ,a) @@ -2703,6 +2708,7 @@ CODE def test_rstrip assert_equal(" hello", " hello ".rstrip) assert_equal("\u3042", "\u3042 ".rstrip) + assert_equal("\u3042", "\u3042\u0000".rstrip) assert_raise(Encoding::CompatibilityError) { "\u3042".encode("ISO-2022-JP").rstrip } end @@ -2723,12 +2729,17 @@ CODE assert_equal(nil, s4.rstrip!) assert_equal("\u3042", s4) + s5 = S("\u3042\u0000") + assert_equal("\u3042", s5.rstrip!) + assert_equal("\u3042", s5) + assert_raise(Encoding::CompatibilityError) { "\u3042".encode("ISO-2022-JP").rstrip! } end def test_lstrip assert_equal("hello ", " hello ".lstrip) assert_equal("\u3042", " \u3042".lstrip) + assert_equal("hello ", "\x00hello ".lstrip) end def test_lstrip_bang @@ -2747,6 +2758,11 @@ CODE s4 = S("\u3042") assert_equal(nil, s4.lstrip!) assert_equal("\u3042", s4) + + s5 = S("\u0000\u3042") + assert_equal("\u3042", s5.lstrip!) + assert_equal("\u3042", s5) + end def test_delete_prefix |