Fixed the corner case bug in `String#{gsub!,sub!}`.

`"a".sub!("a", "a")` should not return `nil`.
parent 54246db0
...@@ -99,7 +99,7 @@ class String ...@@ -99,7 +99,7 @@ class String
raise FrozenError, "can't modify frozen String" if frozen? raise FrozenError, "can't modify frozen String" if frozen?
return to_enum(:gsub!, *args) if args.length == 1 && !block return to_enum(:gsub!, *args) if args.length == 1 && !block
str = self.gsub(*args, &block) str = self.gsub(*args, &block)
return nil if str == self return nil unless self.index(args[0])
self.replace(str) self.replace(str)
end end
...@@ -161,7 +161,7 @@ class String ...@@ -161,7 +161,7 @@ class String
def sub!(*args, &block) def sub!(*args, &block)
raise FrozenError, "can't modify frozen String" if frozen? raise FrozenError, "can't modify frozen String" if frozen?
str = self.sub(*args, &block) str = self.sub(*args, &block)
return nil if str == self return nil unless self.index(args[0])
self.replace(str) self.replace(str)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment