Skip to content

Commit

Permalink
* file.c (rb_file_s_basename): returns new string instead of
Browse files Browse the repository at this point in the history
  shared string from FilePathStringValue().  [ruby-core:24199]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jul 8, 2009
1 parent dddd406 commit ca93e00
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Wed Jul 8 16:47:03 2009 Nobuyoshi Nakada <[email protected]>

* file.c (rb_file_s_basename): returns new string instead of
shared string from FilePathStringValue(). [ruby-core:24199]

2009-07-07 Eric Hodel <[email protected]>

* ext/.document: Update with extensions that appear to have
Expand Down
4 changes: 2 additions & 2 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3104,7 +3104,7 @@ rb_file_s_basename(int argc, VALUE *argv)
}
FilePathStringValue(fname);
if (RSTRING_LEN(fname) == 0 || !*(name = RSTRING_PTR(fname)))
return fname;
return rb_str_new_shared(fname);
name = skipprefix(name);
#if defined DOSISH_DRIVE_LETTER || defined DOSISH_UNC
root = name;
Expand Down Expand Up @@ -3146,7 +3146,7 @@ rb_file_s_basename(int argc, VALUE *argv)
if (NIL_P(fext) || !(f = rmext(p, n, StringValueCStr(fext)))) {
f = n;
}
if (f == RSTRING_LEN(fname)) return fname;
if (f == RSTRING_LEN(fname)) return rb_str_new_shared(fname);
}
basename = rb_str_new(p, f);
rb_enc_copy(basename, fname);
Expand Down
6 changes: 4 additions & 2 deletions test/ruby/test_file_exhaustive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ def test_expand_path

def test_basename
assert_equal(File.basename(@file).sub(/\.test$/, ""), File.basename(@file, ".test"))
assert_equal("", File.basename(""))
assert_equal("foo", File.basename("foo"))
assert_equal("", s = File.basename(""))
assert(!s.frozen?, '[ruby-core:24199]')
assert_equal("foo", s = File.basename("foo"))
assert(!s.frozen?, '[ruby-core:24199]')
assert_equal("foo", File.basename("foo", ".ext"))
assert_equal("foo", File.basename("foo.ext", ".ext"))
assert_equal("foo", File.basename("foo.ext", ".*"))
Expand Down

0 comments on commit ca93e00

Please sign in to comment.