Bugs: Browse | Submit New | Admin

[#3329] String#scan loops forefever if scanned string is modified inside block.

Date:
2006-01-26 08:55
Priority:
3
Submitted By:
Nikolai Lugovoi (meadow)
Assigned To:
Nobody (None)
Category:
Language / Runtime / Core Libraries
State:
Closed
Platform:
 
Summary:
String#scan loops forefever if scanned string is modified inside block.

Detailed description
ruby 1.8.4 (2005-12-24)

Following code loops infinitely:

a = " 12345678 "; a.scan(/\d/) {|s| a[3,2]='test';  s} 

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-05-30 01:52
Sender: Ryan Davis

confirmed.
Date: 2007-05-29 23:47
Sender: Daniel Berger

This was fixed by freezing the yielded object as per ruby-core:
7222. Trying to run the sample code with 1.8.6 raises a
RuntimeError.

Dan
Date: 2006-01-26 20:33
Sender: Paul Duncan

I've posted a comment this on ruby-core at the following URL:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/7220

Basically, I'm not convinced the "fix" to this problem
is better than just leaving things as-is.  My suggestion, and
patch, is a clarification in the documentation that discourages
people from modifying the receiving string inside a String#scan
block.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
status_idOpen2007-05-30 01:52zenspider
resolution_idNone2007-05-30 01:52zenspider
close_date2007-05-30 01:522007-05-30 01:52zenspider
category_idMisc / Other Standard Library2007-05-29 17:49zenspider
category_idLanguage / Runtime / Core Libraries2007-05-29 15:54zenspider