Project

General

Profile

This project is closed and read-only.

Actions

Backport #3200

closed

String#gsub! doesn't error on frozen string

Backport #3200: String#gsub! doesn't error on frozen string

Added by candlerb (Brian Candler) over 16 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
[ruby-core:29784]

Description

=begin
gsub! does not raise an error on a frozen string unless a change is actually made. e.g.

s = "a".freeze
=> "a"
s.gsub!(/b/,'')
=> nil

But this is inconsistent with other mutating methods on frozen strings, e.g.

s.squeeze!
TypeError: can't modify frozen string
from (irb):3:in squeeze!' from (irb):3 from :0 s.tr!('b','c') TypeError: can't modify frozen string from (irb):4:in tr!'
from (irb):4
from :0

Not sure if this unexpected behaviour is "bug" or "feature". The ri documentation of String#gsub! doesn't mention this anomaly.

Tested with ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux] from Ubuntu Karmic
=end

Updated by nobu (Nobuyoshi Nakada) over 16 years ago Actions #1

=begin
1.9.2 does raise an exception, so I guess it would be
"backport".

=end

Updated by jeremyevans0 (Jeremy Evans) about 7 years ago Actions #2

  • Project changed from 2 to 5
  • Description updated (diff)
  • Status changed from Open to Closed
Actions

Also available in: PDF Atom