summaryrefslogtreecommitdiff
path: root/test/ruby/test_string.rb
AgeCommit message (Collapse)Author
2020-09-25Disable deprecation warning by the default [Feature #16345]Nobuyoshi Nakada
And `-w` option turns it on. Notes: Merged: https://github.com/ruby/ruby/pull/3481
2020-09-11Let String#slice! return nil (#3533)Soutaro Matsumoto
Returns `nil` instead of an empty string when non-integer number is given (to make it 2.7 compatible). Notes: Merged-By: soutaro <matsumoto@soutaro.com>
2020-08-31The deprecation of enumerators with block has been withdrawnNobuyoshi Nakada
https://bugs.ruby-lang.org/issues/6670#change-75907
2020-08-19register_fstring: avoid duping the passed string when possibleJean Boussier
If the passed string is frozen, bare and not shared, then there is no need to duplicate it. Ref: 4ab69ebbd7cef8539f687e1f948845d076461dc6 Ref: https://bugs.ruby-lang.org/issues/11386 Notes: Merged: https://github.com/ruby/ruby/pull/3430
2020-08-13rb_str_{index,rindex}_m: Handle /\K/ in patternKasumi Hanazuki
When the pattern Regexp given to String#index and String#rindex contain a /\K/ (lookbehind) operator, these methods return the position where the beginning of the lookbehind pattern matches, while they are expected to return the position where the \K matches. ``` # without patch "abcdbce".index(/b\Kc/) # => 1 "abcdbce".rindex(/b\Kc/) # => 4 ``` This patch fixes this problem by using BEG(0) instead of the return value of rb_reg_search. ``` # with patch "abcdbce".index(/b\Kc/) # => 2 "abcdbce".rindex(/b\Kc/) # => 5 ``` Fixes [Bug #17118] Notes: Merged: https://github.com/ruby/ruby/pull/3414
2020-08-13rb_str_{partition,rpartition}_m: Handle /\K/ in patternKasumi Hanazuki
When the pattern given to String#partition and String#rpartition contain a /\K/ (lookbehind) operator, the methods return strings sliced at incorrect positions. ``` # without patch "abcdbce".partition(/b\Kc/) # => ["a", "c", "cdbce"] "abcdbce".rpartition(/b\Kc/) # => ["abcd", "c", "ce"] ``` This patch fixes the problem by using BEG(0) instead of the return value of rb_reg_search. ``` # with patch "abcdbce".partition(/b\Kc/) # => ["ab", "c", "dbce"] "abcdbce".rpartition(/b\Kc/) # => ["abcdb", "c", "e"] ``` As a side-effect this patch makes String#partition 2x faster when the pattern is a costly Regexp by performing Regexp search only once, which was unexpectedly done twice in the original implementation. Fixes [Bug #17119] Notes: Merged: https://github.com/ruby/ruby/pull/3413
2020-08-12string.c(rb_str_split_m): Handle /\K/ correctlyKasumi Hanazuki
Use BEG(0) instead of the result of rb_reg_search to handle the cases when the separator Regexp contains /\K/ (lookbehind) operator. Fixes [Bug #17113] Notes: Merged: https://github.com/ruby/ruby/pull/3407
2020-07-31Added NUL-contained casesNobuyoshi Nakada
2020-02-23Warn non-nil `$/` [Feature #14240]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/2920
2020-01-16Fix `String#partition`Nobuyoshi Nakada
Split with the matched part when the separator matches the empty part at the beginning. [Bug #11014]
2019-12-20Refined the warning message for $, and $;Nobuyoshi Nakada
[Bug #16438]
2019-12-04Revert "Regexp#match{?} with nil raises TypeError as String, Symbol (#1506)"NARUSE, Yui
This reverts commit 2a22a6b2d8465934e75520a7fdcf522d50890caf. Revert [Feature #13083]
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-10-17Regexp#match{?} with nil raises TypeError as String, Symbol (#1506)Kenichi Kamiya
* {String|Symbol}#match{?} with nil returns falsy To improve consistency with Regexp#match{?} * String#match(nil) returns `nil` instead of TypeError * String#match?(nil) returns `false` instead of TypeError * Symbol#match(nil) returns `nil` instead of TypeError * Symbol#match?(nil) returns `false` instead of TypeError * Prefer exception * Follow empty ENV * Drop outdated specs * Write ruby/spec for above https://github.com/ruby/ruby/pull/1506/files#r183242981 * Fix merge miss
2019-09-25Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans
Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function. Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2019-08-15Fixed heap-use-after-freeNobuyoshi Nakada
* string.c (rb_str_sub_bang): retrieves a pointer to the replacement string buffer just before using it, for the case of replacement with the receiver string itself. [Bug #16105]
2019-07-27Occupy match dataNobuyoshi Nakada
* string.c (rb_str_split_m): occupy match data not to be modified during yielding the block. [Bug #16024]
2019-07-14Check the result of String#-@Nobuyoshi Nakada
2019-07-02Make String#-@ not freeze receiver if called on unfrozen subclass instanceJeremy Evans
rb_fstring behavior in this case is to freeze the receiver. I'm not sure if that should be changed, so this takes the conservative approach of duping the receiver in String#-@ before passing to rb_fstring. Fixes [Bug #15926]
2019-06-29Fixed String#grapheme_clusters with wide encodingsNobuyoshi Nakada
* string.c (get_reg_grapheme_cluster): make regexp from properly encoded sources fro wide-char encodings. [Bug #15965] * regparse.c (node_extended_grapheme_cluster): suppress false duplicated range warning for the time being.
2019-06-29Hoisted out WIDE_ENCODINGSNobuyoshi Nakada
2019-06-19New buffer for shared stringNobuyoshi Nakada
* string.c (rb_str_init): allocate new buffer if the string is shared. [Bug #15937]
2019-06-19Preserve the string content at self-copyingNobuyoshi Nakada
* string.c (rb_str_init): preserve the embedded content when self-copying with a capacity. [Bug #15937]
2019-06-18String#b: Don't depend on dependent stringAlan Wu
Registering a string that depend on a dependent string as fstring can lead to use-after-free. See c06ddfe and 3f95620 for details. The following script triggers use-after-free on trunk, 2.4.6, 2.5.5 and 2.6.3. Credits to @wanabe for using eval as a cross-version way of registering a fstring. ```ruby a = ('j' * 24).b.b eval('', binding, a) p a 4.times { GC.start } p a ``` - string.c (str_replace_shared_without_enc): when given a dependent string, depend on the root of the dependent string. [Bug #15934]
2019-06-01Update String#crypt tests to work on OpenBSDJeremy Evans
Skip the webrick httpauth tests that use crypt when testing on OpenBSD. Fixes [Bug #11363]
2019-04-27Get rid of indirect sharingNobuyoshi Nakada
* string.c (str_duplicate): share the root shared string if the original string is already sharing, so that all shared strings refer the root shared string directly. indirect sharing can cause a dangling pointer. [Bug #15792]
2019-04-18string.c: warn non-nil $;nobu
* string.c (rb_str_split_m): warn use of non-nil $;. * string.c (rb_fs_setter): warn when set to non-nil value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-26string.c: remove the deprecation warnings of `String#bytes` with blockmame
And its friends: lines, chars, grapheme_clusters, and codepoints. [Feature #6670] [ruby-core:90728] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66579 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-26Revert "string.c: remove the deprecation warnings of `String#bytes` with block"mame
Forgot to write the ticket number in the commit log... git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-26string.c: remove the deprecation warnings of `String#bytes` with blockmame
And its friends: lines, chars, grapheme_clusters, and codepoints. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04change diaeresis from above to below for better visibilityduerst
In test/ruby/test_regexp.rb and test/ruby/test_string.rb, change some instances of COMBINING DIAERESIS (U+0308, above) to COMBINING DIAERESIS BELOW (U+0324) to make it more easily visible in test output, particularly in the context of double quotes surrounding strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-24assertions for r65956nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-24Don't use single byte optimization on grapheme clustersnaruse
Unicode Text Segmentation considers CRLF as a character. [Bug #15337] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23test/lib/test/unit/assertions.rb: skip memory leak checkk0kubun
for all test cases on MJIT. In addition to those 2 tests, TestAutoload#test_no_leak newly failed and most of assert_no_memory_leak usages are likely to randomly fail. Let me just skip all of them but let's revisit this to check it properly later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-22test/ruby/test_string.rb: skip test_crypt for MJIT againk0kubun
Partially reverting r65285. Actually this one is failing due to memory consumption on MJIT, so this seems not catching the bug of MJIT. test/ruby/test_io.rb: unify the skip message with it git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-21try to remove some test skips for MJITk0kubun
Eric Wong made some effort to keep compatibility around fd with MJIT. Also I'm hoping r65279 (and r65280) eliminates major MJIT bugs, so I want to start solely testing MJIT. Other test skips branched by MJIT enablement seemed reasonable to me. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-26test: skip 2 major unstable tests with MJITk0kubun
for CI with cppflags=-DMJIT_FORCE_ENABLE. Since I have no idea to fix this immediately, let me skip this for now and take a look later. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-24string.c: fix scanned substring with `\K`nobu
* string.c (scan_once): fix the matched substring with `\K`, the beginning of that string may differ from the matched position. [ruby-core:86663] [Bug #14707] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-16string.c: fix checking ordernobu
* string.c (str_undump): check for suffix before if Unicode escape conflicts with it. the message "but used force_encoding" sounds strange when it is not used. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-22fix each_grapheme_cluster's size [Bug #14363]naruse
From: Hugo Peixoto <hugo.peixoto@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-22Revert "each_grapheme_cluster shouldn't return size [Bug #14363]"naruse
This reverts commit r62887. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-22each_grapheme_cluster shouldn't return size [Bug #14363]naruse
From: Stefan Schüßler <mail@stefanschuessler.de> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15string.c: split with blocknobu
* string.c (rb_str_split_m): yield each split substrings if the block is given, instead of returing the array. [Feature #4780] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-15test_array.rb (test_slice!): moved misplaced testnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-31trick ruby-mode.el by heredocsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-25string.c: clear substring code rangenobu
* string.c (str_substr): substring of broken code range string may be valid or broken. patch by tommy (Masahiro Tomita) at [ruby-dev:50430] [Bug #14388]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-29string.c: chomp rs at the endnobu
* string.c (rb_str_enumerate_lines): should chomp record separator only, but not a newline, at the end of the receiver as well as middle, if the separator is given. [ruby-core:84552] [Bug #14257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-21Don't allow mixed escapenaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-21move dump format validation into parsing epiloguenaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61380 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-21fix escapes in undumpnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61379 b2dd03c8-39d4-4d8f-98ff-823fe69b080e