Skip to content

Commit

Permalink
Merge pull request #823 from danshultz/string_chomp_passed_nil
Browse files Browse the repository at this point in the history
string.chomp!(nil) returns nil
  • Loading branch information
alex committed Oct 13, 2013
2 parents c924603 + 8a05048 commit dce3eef
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 0 additions & 2 deletions spec/tags/core/string/chomp_tags.txt
@@ -1,4 +1,2 @@
fails:String#chomp! when passed nil returns nil
fails:String#chomp! when passed nil returns nil when self is empty
fails:String#chomp removes the final carriage return, newline from a non-ASCII String
fails:String#chomp! removes the final carriage return, newline from a non-ASCII String
2 changes: 2 additions & 0 deletions tests/objects/test_stringobject.py
Expand Up @@ -440,6 +440,8 @@ def test_chomp(self, space):
assert w_res is space.w_nil
w_res = space.execute('return "".chomp!')
assert w_res is space.w_nil
w_res = space.execute('return "abc".chomp!(nil)')
assert w_res is space.w_nil
w_res = space.execute('return "abc\\r".chomp!("")')
assert w_res is space.w_nil

Expand Down
2 changes: 1 addition & 1 deletion topaz/objects/stringobject.py
Expand Up @@ -1212,7 +1212,7 @@ def method_chomp_i(self, space, w_newline=None):
if w_newline is None:
w_newline = space.globals.get(space, "$/")
if w_newline is space.w_nil:
return self
return space.w_nil
newline = space.str_w(space.convert_type(w_newline, space.w_string, "to_str"))
if newline and newline in "\n\r":
newline = None
Expand Down

0 comments on commit dce3eef

Please sign in to comment.