Issue #16024 has been updated by qitar888 (Chia-sheng Chen).


tksotn (TAKASHI OOTANI) wrote:
> $ ruby -v
> ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
> $ cat foo
> str = "aaa,bbb;ccc,ddd"
> n=0
> str.split(/[;,]/) do |word|
>     n+=1
>     p [n,word.gsub(/\w/,"A")]
> end
> $ ruby foo
> [1, "AAA"]
> [2, "\u0000AAA,AAA;AAA,AAA"]
> $
> 
> ### expected output:
> [1, "AAA"]
> [2, "AAA"]
> [3, "AAA"]
> [4, "AAA"]
> 
> $ cat bar
> str = "aaa\nb\nccc\nddd\n"
> n=0
> str.split(/\n/) do |line|
>     n+=1
>     p [n,line.gsub(/.*/,"A")]
> end
> $ ruby bar
> => infinite loop

Hi,

I tried with `str.split().each &block` and things work just fine for me.




----------------------------------------
Bug #16024: String#split with block. cannot use Regexp in the block.
https://bugs.ruby-lang.org/issues/16024#change-80129

* Author: tksotn (TAKASHI OOTANI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
$ cat foo
str = "aaa,bbb;ccc,ddd"
n=0
str.split(/[;,]/) do |word|
    n+=1
    p [n,word.gsub(/\w/,"A")]
end
$ ruby foo
[1, "AAA"]
[2, "\u0000AAA,AAA;AAA,AAA"]
$

### expected output:
[1, "AAA"]
[2, "AAA"]
[3, "AAA"]
[4, "AAA"]

$ cat bar
str = "aaa\nb\nccc\nddd\n"
n=0
str.split(/\n/) do |line|
    n+=1
    p [n,line.gsub(/.*/,"A")]
end
$ ruby bar
=> infinite loop




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>