summaryrefslogtreecommitdiff
path: root/test/ruby/test_string.rb
AgeCommit message (Collapse)Author
2025-12-11[Bug #19558] Allow ASCII range to mix with Unicode dumpNobuyoshi Nakada
2025-12-11Allow String#strip etc. to take optional character selectorsShugo Maeda
[Feature #21552] Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05Refine non-nil warnings for the deprecated variablesNobuyoshi Nakada
2025-12-05[Bug #21764] Propagate the encoding of ID to warningNobuyoshi Nakada
2025-12-02Avoid leaking fd in uminus_no_embed testJohn Hawthorn
2025-11-07Don't modify fstrings in rb_str_tmp_frozen_no_embed_acquireJohn Hawthorn
[Bug #21671]
2025-11-01Fix memory leak in String#encode when StringValue raisesPeter Zhu
The following script leaks memory: 10.times do 100_000.times do "\ufffd".encode(Encoding::US_ASCII, fallback: proc { Object.new }) rescue end puts `ps -o rss= -p #{$$}` end Before: 450244 887748 1325124 1762756 2200260 2637508 3075012 3512516 3950020 4387524 After: 12236 12364 12748 13004 13388 13516 13772 13772 13772 13772
2025-10-29Fix memory leak in String#encode when fallback too bigPeter Zhu
The following script leaks memory: 10.times do 100_000.times do "\ufffd".encode(Encoding::US_ASCII, fallback: proc { "\uffee" }) rescue end puts `ps -o rss= -p #{$$}` end Before: 451196 889596 1328252 1766524 2204668 2643068 3081724 3520124 3958524 4396796 After: 12800 13056 13184 13312 13312 13312 13312 13312 13312 13312
2025-10-28Add a custom error class to TestString#test_encode_fallback_raise_memory_leakPeter Zhu
This prevents a generic RuntimeError from being raised so we can ensure that the correct error is being rescued.
2025-10-28Fix TestString#test_encode_fallback_raise_memory_leakPeter Zhu
The method and aref cases need to accept a parameter.
2025-10-24Fix memory leak of transcoding when fallback raisesPeter Zhu
When the fallback function in transcode_loop raises, it will leak the memory in rb_econv_t. The following script reproduces the leak: 10.times do 100_000.times do "\ufffd".encode(Encoding::US_ASCII, fallback: proc { raise }) rescue end puts `ps -o rss= -p #{$$}` end Before: 451196 889980 1328508 1767676 2206460 2645372 3083900 3522428 3960956 4399484 After: 12508 12636 12892 12892 13148 13404 13532 13788 13916 13916
2025-08-19Change TestString#test_ascii_incomat_inspect to use ↵Peter Zhu
EnvUtil.with_default_external
2025-08-11Update test_string.rbErim Icel
2025-08-11Optimize `str_casecmp` length check using pointer endErim Icel
2025-07-28Update comments for pack/unpack tests [ci skip]Nobuyoshi Nakada
More comprehensive pack/unpack tests are in test_pack.rb.
2025-07-27Add test for `String#byteslice` with multibyte charactersErim Icel
2025-05-29[Bug #21380] Prohibit modification in String#split blockNobuyoshi Nakada
Reported at https://hackerone.com/reports/3163876 Notes: Merged: https://github.com/ruby/ruby/pull/13462
2025-03-04Move in-place interning spec to Ruby's testsJean Boussier
Fix: https://github.com/ruby/spec/issues/1249 JRuby and TruffleRuby can't implement this behavior. While quite a lot of code out there relies on it, if it's not implemented it will simply result in sligthly less efficient code, so not the end of the world. Notes: Merged: https://github.com/ruby/ruby/pull/12850
2024-11-26Many of Oniguruma functions need valid encoding stringsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12169
2024-11-26Check negative integer underflowNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12169
2024-10-03Rename size_pool -> heapMatt Valentine-House
Now that we've inlined the eden_heap into the size_pool, we should rename the size_pool to heap. So that Ruby contains multiple heaps, with different sized objects. The term heap as a collection of memory pages is more in memory management nomenclature, whereas size_pool was a name chosen out of necessity during the development of the Variable Width Allocation features of Ruby. The concept of size pools was introduced in order to facilitate different sized objects (other than the default 40 bytes). They wrapped the eden heap and the tomb heap, and some related state, and provided a reasonably simple way of duplicating all related concerns, to provide multiple pools that all shared the same structure but held different objects. Since then various changes have happend in Ruby's memory layout: * The concept of tomb heaps has been replaced by a global free pages list, with each page having it's slot size reconfigured at the point when it is resurrected * the eden heap has been inlined into the size pool itself, so that now the size pool directly controls the free_pages list, the sweeping page, the compaction cursor and the other state that was previously being managed by the eden heap. Now that there is no need for a heap wrapper, we should refer to the collection of pages containing Ruby objects as a heap again rather than a size pool Notes: Merged: https://github.com/ruby/ruby/pull/11771
2024-09-09Implement String#append_as_bytes(String | Integer, ...)Jean Boussier
[Feature #20594] A handy method to construct a string out of multiple chunks. Contrary to `String#concat`, it doesn't do any encoding negociation, and simply append the content as bytes regardless of whether this result in a broken string or not. It's the caller responsibility to check for `String#valid_encoding?` in cases where it's needed. When passed integers, only the lower byte is considered, like in `String#setbyte`. Notes: Merged: https://github.com/ruby/ruby/pull/11552
2024-07-26Fix memory leak in String#start_with? when regexp times outPeter Zhu
[Bug #20653] This commit refactors how Onigmo handles timeout. Instead of raising a timeout error, onig_search will return a ONIGERR_TIMEOUT which the caller can free memory, and then raise a timeout error. This fixes a memory leak in String#start_with when the regexp times out. For example: regex = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001) str = "a" * 1000000 + "x" 10.times do 100.times do str.start_with?(regex) rescue end puts `ps -o rss= -p #{$$}` end Before: 33216 51936 71152 81728 97152 103248 120384 133392 133520 133616 After: 14912 15376 15824 15824 16128 16128 16144 16144 16160 16160 Notes: Merged: https://github.com/ruby/ruby/pull/11247
2024-05-28Stop marking chilled strings as frozenÉtienne Barrié
They were initially made frozen to avoid false positives for cases such as: str = str.dup if str.frozen? But this may cause bugs and is generally confusing for users. [Feature #20205] Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-04-17test_uplus_minus: Use a different string literalJean Boussier
This test fail relatively frequently and it's unclear what is happening. ``` str: {"address":"0x7fbdeb26d4e0", "type":"STRING", "shape_id":1, "slot_size":40, "class":"0x7fbdd1e0ec50", "frozen":true, "embedded":true, "fstring":true, "bytesize":3, "value":"bar", "encoding":"UTF-8", "coderange":"7bit", "memsize":40, "flags":{"wb_protected":true, "old":true, "uncollectible":true, "marked":true}} bar: {"address":"0x7fbdd0a8b138", "type":"STRING", "shape_id":1, "slot_size":40, "class":"0x7fbdd1e0ec50", "frozen":true, "embedded":true, "fstring":true, "bytesize":3, "value":"bar", "encoding":"UTF-8", "coderange":"7bit", "memsize":40, "flags":{"wb_protected":true}} ``` The `"bar".freeze` literal correctly put an old-gen fstring on the stack. But `-%w(b a r).join('')` returns a young-gen fstring, which suggest it somehow failed to find the old one in the `frozen_strings` table. This could be caused by another test corrupting the table, or corrupting the `"bar"` fstring. By using a different literal value we can learn whether the bug is specific to `"bar"` (used in many tests) or more general.
2024-04-15Include more debug information in test_uplus_minusJean Boussier
2024-04-15Add more assertions in `test_uplus_minus`Jean Boussier
Not along after 1b830740ba8371c4bcfdfc6eb2cb7e0ae81a84e0 CI started to rarely fail this test: ``` TestString#test_uplus_minus: Test::Unit::AssertionFailedError: uminus deduplicates [Feature #13077]. 1) Failure: TestString#test_uplus_minus [/tmp/ruby/src/trunk/test/ruby/test_string.rb:3368]: ``` It's unclear what is going on, but one possibility is that `"bar".freeze` might no longer compile correctly. Another possibility is that another test redefine `String#freeze`, causing `opt_str_freeze` to no longer return an `fstring`.
2024-04-04Prevent "ambiguous first argument" warningsYusuke Endoh
2024-03-27[DOC] remove repetitive words in commentscrazeteam
Signed-off-by: crazeteam <lilujing@outlook.com>
2024-03-25[Bug #20389] Chilled string cannot be a shared rootNobuyoshi Nakada
2024-03-20Avoid deprecation warnings in TestStringJean Boussier
2024-03-19Implement chilled stringsÉtienne Barrié
[Feature #20205] As a path toward enabling frozen string literals by default in the future, this commit introduce "chilled strings". From a user perspective chilled strings pretend to be frozen, but on the first attempt to mutate them, they lose their frozen status and emit a warning rather than to raise a `FrozenError`. Implementation wise, `rb_compile_option_struct.frozen_string_literal` is no longer a boolean but a tri-state of `enabled/disabled/unset`. When code is compiled with frozen string literals neither explictly enabled or disabled, string literals are compiled with a new `putchilledstring` instruction. This instruction is identical to `putstring` except it marks the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags. Chilled strings have the `FL_FREEZE` flag as to minimize the need to check for chilled strings across the codebase, and to improve compatibility with C extensions. Notes: - `String#freeze`: clears the chilled flag. - `String#-@`: acts as if the string was mutable. - `String#+@`: acts as if the string was mutable. - `String#clone`: copies the chilled flag. Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-12[Bug #20277] Remove stale `String` test conditionalsNobuyoshi Nakada
These instance variables for conditional execution have remained unchanged for nearly twenty years, since YARV merger.
2024-02-27Add a failing test for https://bugs.ruby-lang.org/issues/20305.Fable Phippen
This bug demonstrates the issue I reported. It passes on commit https://github.com/ruby/ruby/commit/114e71d06280f9c57b9859ee4405ae89a989ddb6 but does not pass on commit (the immediate child of the above commit) https://github.com/ruby/ruby/commit/1d2d25dcadda0764f303183ac091d0c87b432566
2024-02-22Skip under_gc_compact_stress on s390x (#10073)Takashi Kokubun
2024-02-22[Bug #20292] Truncate embedded string to new capacityNobuyoshi Nakada
2024-01-16Fix coderange of invalid_encoding_string.<<(ord)tompng
Appending valid encoding character can change coderange from invalid to valid. Example: "\x95".force_encoding('sjis')<<0x5C will be a valid string "\x{955C}"
2024-01-08Fix memory leak in grapheme clustersPeter Zhu
[Bug #20150] String#grapheme_cluters and String#each_grapheme_cluster leaks memory because if the string is not UTF-8, then the created regex will not be freed. For example: str = "hello world".encode(Encoding::UTF_32LE) 10.times do 1_000.times do str.grapheme_clusters end puts `ps -o rss= -p #{$$}` end Before: 26000 42256 59008 75792 92528 109232 125936 142672 159392 176160 After: 9264 9504 9808 10000 10128 10224 10352 10544 10704 10896
2023-12-23Fix String#sub for GC compactionPeter Zhu
The test fails when RGENGC_CHECK_MODE is turned on: TestString#test_sub_gc_compact_stress = 9.42 s 1) Failure: TestString#test_sub_gc_compact_stress [test/ruby/test_string.rb:2089]: <"aaa [amp] yyy"> expected but was <"aaa [] yyy">.
2023-12-17Stir the hash value more with encoding indexNobuyoshi Nakada
2023-12-16[Bug #20068] Encoding does not matter to empty stringsNobuyoshi Nakada
2023-12-13Make String#chomp! raise ArgumentError for 2+ arguments if string is emptyJeremy Evans
String#chomp! returned nil without checking the number of passed arguments in this case.
2023-12-01Make String#undump compaction safePeter Zhu
2023-11-29Guard match from GC in String#gsubPeter Zhu
We need to guard match from GC because otherwise it could end up being reclaimed or moved in compaction.
2023-11-27Guard match from GC when scanning stringPeter Zhu
We need to guard match from GC because otherwise it could end up being reclaimed or moved in compaction.
2023-09-01Add regression tests for start_with?/delete_prefixywenc
Notes: Merged: https://github.com/ruby/ruby/pull/8348
2023-08-26[Bug #19784] Fix behaviors against prefix with broken encodingNobuyoshi Nakada
- String#start_with? - String#delete_prefix - String#delete_prefix! Notes: Merged: https://github.com/ruby/ruby/pull/8296
2023-08-26Split string testsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8296
2023-07-15[Bug #19769] Fix range of size 1 in `String#tr`alexandre184
Notes: Merged: https://github.com/ruby/ruby/pull/8080 Merged-By: nobu <nobu@ruby-lang.org>
2023-06-28[Bug #19748] Fix out-of-bound access in `String#byteindex`Nobuyoshi Nakada