# Re: RubyForge bug fixes

**URL:** <https://www.ruby-forum.com/t/re-rubyforge-bug-fixes/137260>\
**Category:** IronRuby\
**Created:** [May 10, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/re-rubyforge-bug-fixes/137260 "2008-05-10T22:02:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksunair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b19c9b/32.png) [@ksunair](https://www.ruby-forum.com/u/ksunair)\
**Post date:** [May 10, 2008, 10:02pm UTC](https://www.ruby-forum.com/t/re-rubyforge-bug-fixes/137260/1 "2008-05-10T22:02:31Z")

</div>

Quick question, are these following assertions are correct?  
Â Â Â should\_raise(TypeError){ File.basename(1) }  
Â Â Â should\_raise(TypeError){ File.basename(“bar.txt”, 1) }  
Â Â Â should\_raise(TypeError){ File.basename(true) }  
I was expecting all the above three should be ArgumentError than  
TypeError, until unless, you expect it to be TypeError, when I run the  
changes I have made for the all the above three by default you get the  
following error

> > > File.basename(1)  
> > > :0:in `Initialize##1': wrong number or type of arguments for `basename’  
> > > (Argumen  
> > > tError)  
> > > let me know if you would like me to validate and force throw TypeError  
> > > execption.  
> > > Also, in the basename\_spec the test setup has wrong parameter on  
> > > File.open(@name, ‘w+’), if I change it to ‘w’, the test runs fine  
> > > otherwise none of the test works.

Thanks,

----- Original Message ----  
From: John L. (IRONRUBY) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: IronRuby External Code R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Cc: “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Saturday, May 10, 2008 3:16:08 AM  
Subject: [Ironruby-core] RubyForge bug fixes

tfpt review /shelveset:merge-3;REDMOND\jflam

Ruby only

This shelveset fixes a number of open bugs on Rubyforge and adds some  
features that we need to get the latest rubinius specs running.

MatchDataOps:

-Â Â Â we used to alias MatchData to  
System.Text.RegularExpressions.Match. However, to fully implement  
MatchData we need to also hold onto a reference to the original string  
that we matched against. A new MatchData type was created (MatchData.cs)  
which wraps the existing .NET Match object. This also touches  
MutableStringOps.cs, RubyOps.cs, RubyScope.cs,  
SpecialGlobalVariableInfo.cs  
-Â Â Â finished implementing all methods. 16 out of 16 specs pass  
-Â Â Â implemented to\_a which closes bug #19903

RegexpOps:

-Â Â Â added ctor overload to close bug #19927  
-Â Â Â made some changes to return MatchData objects instead of Match  
objects  
-Â Â Â made some changes to return boxed integers via  
RuntimeHelpers.Int32ToObject() instead of explicit boxing. This also  
touches MutableStringOps.cs

TimeOps:

-Â Â Â removed overloaded constructors to close bug #19956. But this  
exposes a new problem about Type aliasing that is described by bug 20035  
(referencing a System::DateTime explicitly does not allow you to call  
the .NET constructors - only the Ruby-defined constructors).  
-Â Â Â fixed Time#- bug - #19955

ModuleOps:

-Â Â Â fixed some very old bugs #15996, #15995 related to including  
non-sensible things (include 1, include nil). RequireNonClasses() method  
now throws the correct Ruby exceptions. This also touches  
SingletonOps.cs

MutableStringOps:

-Â Â Â added an implementation of String#rindex which closes #19904. We  
pass all specs except for 4 which fail because of differences between  
.NET regex and Ruby regex.

Dir.cs:

-Â Â Â cleaned up some code here, was about to work on glob  
implementation (bugs #19843 #19950, but handed off to Curt)

FileOps.cs:

-Â Â Â added an implementation of File#basename which closes #19905.  
passes all specs except for one which is wrong, and one which is  
unix-specific. These things are likely bugs in Ruby.

Â Â #File.basename(‘baz.rb’, ‘z.rb’).should == ‘ba’ – bad test  
Â Â #File.basename(“bar.txt.exe”, “.txt.exe”).should == “bar” -  
unix-only, should be wrapped in platform

-Â Â Â added an implementation of File.file? to close #19949

MutableString.cs:

-Â Â Â added a static Empty MutableString  
-Â Â Â added delegation thunks to LastIndexOf()  
-Â Â Â fixed our Equals() implementation to correctly distinguish  
between different types of strings (CLR vs. MutableString)

File.cs:

-Â Â Â fixes a bug related to what “w+” means in .NET. - its  
FileMode.OpenOrCreate

Fixed bug #19885 by adding the -I command line switch which lets you  
specify the library load path. I’ve redefined our internal alias.txt  
file to generate aliases for rbd and rbx that include a pointer to where  
the MRI libs are stored in our layout.

Fixed bug #17810, which was a long-standing perf bug.

Fixed bug #20007, by allowing users to pass nothing for  
attr\_accessor/reader/writer. This is really a bug in Ruby, but the  
current implementations allow this behavior, and there are apps that  
actually depend on it (RbYAML).

Thanks,  
-John

---

<div class="post-metadata">

**Author:** ![ksunair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b19c9b/32.png) [@ksunair](https://www.ruby-forum.com/u/ksunair)\
**Post date:** [May 10, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/re-rubyforge-bug-fixes/137260/2 "2008-05-10T22:27:08Z")

</div>

Unnikrishnan N.:

> Quick question, are these following assertions are correct?
> 
> ```
> should_raise(TypeError){ File.basename(1) }
> should_raise(TypeError){ File.basename("bar.txt", 1) }
> should_raise(TypeError){ File.basename(true) }
> 
> ```

Yes they are. You can easily verify this in MRI yourself.

In first and third cases, it hits the overload that accepts a nullable  
object as the first parameter. The TypeError is raised via  
Protocols.CastToString().

In the second case, it also hits an overload that accepts a nullable  
object as its second parameter, which raises TypeError via  
Protocols.CastToString().

FYI, this is the implementation of #basename that I have in my  
shelveset. It passes all of the (valid) specs - there are some  
legitimate bugs in our old copy of the specs (I haven’t checked with the  
latest version of the rubinius specs - I’ll do that next week). I’m a  
bit worried about how I’m handling the special cases for Windows.

[RubyMethod(“basename”, RubyMethodAttributes.PublicSingleton)]  
public static MutableString/_!_/ Basename(CodeContext/_!_/ context,  
object/_!_/ self, [NotNull]MutableString/_!_/ path,  
[NotNull]MutableString/_!_/ extensionFilter) {  
if (path.Length == 0)  
return path;

```
MutableString trimmedPath = TrimTrailingSlashes(path);

// Special cases of drive letters C:\\ or C:/
if (trimmedPath.Length == 2)
    if (Char.IsLetter(trimmedPath.GetChar(0)) && 

```

trimmedPath.GetChar(1) == ‘:’)  
return Kernel.FlowTaint(context, path, (path.Length \> 2 ?  
MutableString.Create(path.GetChar(2).ToString()) :  
MutableString.Create(String.Empty)));

```
string trimmedPathAsString = trimmedPath.ConvertToString();
if (trimmedPathAsString == "/")
    return trimmedPath;

string filename = 

```

System.IO.Path.GetFileName(trimmedPath.ConvertToString());

```
// Handle UNC host names correctly
string root = 

```

System.IO.Path.GetPathRoot(trimmedPath.ConvertToString());  
if (extensionFilter.Length == 0)  
return trimmedPathAsString == root ? MutableString.Create(root)  
: MutableString.Create(filename);

```
string fileExtension = System.IO.Path.GetExtension(filename);
string basename = 

```

System.IO.Path.GetFileNameWithoutExtension(filename);

```
string result = WildcardExtensionMatch(fileExtension, 

```

extensionFilter.ConvertToString()) ? basename : filename;  
return Kernel.FlowTaint(context, self, (result.Equals(root) ?  
MutableString.Create(root) : MutableString.Create(result)));  
}

[RubyMethod(“basename”, RubyMethodAttributes.PublicSingleton)]  
public static MutableString/_!_/ Basename(CodeContext/_!_/ context,  
object/_!_/ self, [NotNull]MutableString/_!_/ path) {  
return Basename(context, self, path, MutableString.Empty);  
}

[RubyMethod(“basename”, RubyMethodAttributes.PublicSingleton)]  
public static MutableString/_!_/ Basename(CodeContext/_!_/ context,  
object/_!_/ self, object path, object extension) {  
return Basename(context, self, Protocols.CastToString(context,  
path), Protocols.CastToString(context, extension));  
}

[RubyMethod(“basename”, RubyMethodAttributes.PublicSingleton)]  
public static MutableString/_!_/ Basename(CodeContext/_!_/ context,  
object/_!_/ self, object path) {  
return Basename(context, self, Protocols.CastToString(context,  
path));  
}

> Also, in the basename\_spec the test setup has wrong parameter on  
> File.open(@name, ‘w+’), if I change it to ‘w’, the test runs fine  
> otherwise none of the test works.

This is correct. There is a bug in how we map the semantics of ‘w+’ to  
.NET IO. It’s fixed in my shelveset.

Thanks,  
-John
