Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/load.c b/load.c
- index 00ccb6c..580b9f1 100644
- --- a/load.c
- +++ b/load.c
- @@ -380,9 +380,9 @@ search_required(VALUE fname, volatile VALUE *path)
- if ((tmp = rb_find_file(fname)) != 0) {
- tmp = rb_file_expand_path(tmp, Qnil);
- ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
- -// if (!rb_feature_p(ftptr, ext, Qtrue, Qtrue, 0)) {
- + // if (!rb_feature_p(ftptr, ext, Qtrue, Qtrue, 0)) {
- *path = tmp;
- -// }
- + // }
- return 'r';
- }
- return 0;
- diff --git a/objc.m b/objc.m
- index e098a86..a0bccc8 100644
- --- a/objc.m
- +++ b/objc.m
- @@ -192,13 +192,42 @@ rb_objc_symbolize_address(void *addr, void **start, char *name,
- VALUE
- rb_file_expand_path(VALUE fname, VALUE dname)
- {
- - NSString *res = [(NSString *)fname stringByExpandingTildeInPath];
- - if (![res isAbsolutePath]) {
- - NSString *dir = dname != Qnil
- - ? (NSString *)dname
- - : [[NSFileManager defaultManager] currentDirectoryPath];
- - res = [dir stringByAppendingPathComponent:res];
- + NSString *res = (NSString *)StringValue(fname);
- +
- + // If the original path starts with "/private", stringByStandardizingPath:
- + // and stringByResolvingSymlinksInPath: remove the "/private" prefix if that path resolves
- + // to a directory in "/". MRI, however, doesn't do that. So we replace the prefix with our own
- + // so the Cocoa methods won't treat it as "/private" and replace it again in the end _if_
- + // the expanded path still has our prefix.
- + BOOL private = [res hasPrefix:@"/private"];
- + if (private) {
- + res = [@"/__mr_private__" stringByAppendingPathComponent:[res substringFromIndex:8]];
- }
- +
- + if ([res isAbsolutePath]) {
- + res = [res stringByResolvingSymlinksInPath];
- + } else {
- + NSString *dir = dname != Qnil ?
- + (NSString *)dname : [[NSFileManager defaultManager] currentDirectoryPath];
- +
- + if (![dir isAbsolutePath]) {
- + dir = (NSString *)rb_file_expand_path((VALUE)dir, Qnil);
- + }
- +
- + // stringByStandardizingPath does not expand "/." to "/"
- + if ([res isEqualTo:@"."] && [dir isEqualTo:@"/"]) {
- + return (VALUE)[@"/" mutableCopy];
- + } else {
- + res = [dir stringByAppendingPathComponent:res];
- + }
- +
- + res = [res stringByStandardizingPath];
- + }
- +
- + if (private && [res hasPrefix:@"/__mr_private__"]) {
- + res = [@"/private" stringByAppendingPathComponent:[res substringFromIndex:15]];
- + }
- +
- return (VALUE)[res mutableCopy];
- }
- diff --git a/spec/frozen/core/file/expand_path_spec.rb b/spec/frozen/core/file/expand_path_spec.rb
- index e896ac4..f07868e 100644
- --- a/spec/frozen/core/file/expand_path_spec.rb
- +++ b/spec/frozen/core/file/expand_path_spec.rb
- @@ -67,10 +67,16 @@ describe "File.expand_path" do
- File.expand_path('~/').should == ENV['HOME']
- File.expand_path('~/..badfilename').should == "#{ENV['HOME']}/..badfilename"
- File.expand_path('..').should == Dir.pwd.split('/')[0...-1].join("/")
- - File.expand_path('//').should == '//'
- File.expand_path('~/a','~/b').should == "#{ENV['HOME']}/a"
- end
- + not_compliant_on :macruby do
- + it "leaves multiple prefixed slashes untouched" do
- + File.expand_path('//').should == '//'
- + File.expand_path('////').should == '////'
- + end
- + end
- +
- it "raises an ArgumentError if the path is not valid" do
- lambda { File.expand_path("~a_fake_file") }.should raise_error(ArgumentError)
- end
- @@ -85,7 +91,7 @@ describe "File.expand_path" do
- end
- end
- - it "raises an ArgumentError is not passed one or two arguments" do
- + it "raises an ArgumentError if not passed one or two arguments" do
- lambda { File.expand_path }.should raise_error(ArgumentError)
- lambda { File.expand_path '../', 'tmp', 'foo' }.should raise_error(ArgumentError)
- end
- diff --git a/spec/frozen/tags/macruby/core/file/expand_path_tags.txt b/spec/frozen/tags/macruby/core/file/expand_path_tags.txt
- index 26a751e..b33331c 100644
- --- a/spec/frozen/tags/macruby/core/file/expand_path_tags.txt
- +++ b/spec/frozen/tags/macruby/core/file/expand_path_tags.txt
- @@ -1,7 +1,2 @@
- -critical:File.expand_path raises an ArgumentError is not passed one or two arguments
- critical:File.expand_path raises a TypeError if not passed a String type
- -fails:File.expand_path converts a pathname to an absolute pathname, using a complete path
- -fails:File.expand_path expand path with
- -fails:File.expand_path expand_path for commoms unix path give a full path
- -fails:File.expand_path raises an ArgumentError if the path is not valid
- -fails:File.expand_path expands /./dir to /dir
- +fails:File.expand_path raises an ArgumentError if the path is not valid
- \ No newline at end of file
- diff --git a/spec/macruby/core/file_spec.rb b/spec/macruby/core/file_spec.rb
- new file mode 100644
- index 0000000..47c1696
- --- /dev/null
- +++ b/spec/macruby/core/file_spec.rb
- @@ -0,0 +1,26 @@
- +# TODO
- +# require File.expand_path('../spec_helper', __FILE__)
- +# require File.expand_path('../spec_helper.rb', __FILE__)
- +
- +require File.dirname(__FILE__) + "/../spec_helper"
- +
- +describe "File#expand_path" do
- + it "returns path prefixed with '/private/tmp' if the original path has the '/private' prefix and expands to '/tmp'" do
- + File.expand_path('/private/tmp').should == '/private/tmp'
- + File.expand_path('/private/bin').should == '/private/bin'
- + File.expand_path('/private/foo').should == '/private/foo'
- + File.expand_path('/private/../foo').should == '/foo'
- + File.expand_path('/private/tmp/foo').should == '/private/tmp/foo'
- + File.expand_path('/private/bin/foo').should == '/private/bin/foo'
- + File.expand_path('/private/foo/../tmp').should == '/private/tmp'
- + File.expand_path('/private/private').should == '/private/private'
- + File.expand_path('/private/private/private').should == '/private/private/private'
- + end
- +
- + it "removes prefixed slashes, which isn't done by MRI" do
- + File.expand_path('//').should == '/'
- + File.expand_path('////').should == '/'
- + File.expand_path('////foo').should == '/foo'
- + File.expand_path('////foo//bar').should == '/foo/bar'
- + end
- +end
- \ No newline at end of file
Add Comment
Please, Sign In to add comment