Skip to content

Loading…

JRUBY-2724: I've added some tests and I tried to fix unc pathing #178

Merged
merged 1 commit into from

2 participants

@lukefx
JRuby Team member

It's not great, but passes some UNC cases.
Maybe the entire function should be rewritten with some regex that treats the various edge cases.

@headius
JRuby Team member

I'm game to get this into 1.7.1. How do we feel about this?

@lukefx
JRuby Team member

Let me know if needs more test or whatever...

@headius headius merged commit ad60957 into jruby:master
@headius headius added a commit that referenced this pull request
@headius headius Squashed 'spec/ruby/' changes from cfdf72f..70b1140
70b1140 Spec the default values of IO#sync for standard streams.
7753d2f Reorder Zlib deflate specs
76488f6 Fix warning in Zlib deflate spec
763d9ea Add specs for streaming in inflate processing
f484f34 Solaris 10 on x86 wrongly returns ai_pprotocol as 0
a5c0605 Remove bad spec
8b118fd Specify new behavior for Enumerable{chunk,slice_before}
5885e2b Initial spec for Queue#close and Queue#closed?
ba17b3d Spec for the new behavior of Kernel#loop
f59a862 No silent rescue in Comparable#<=> is now released behavior in 2.3
9a20b87 Treat paths with unicode characters as binary to avoid depending on the locale.
5ab735b Merge pull request #180 from ruby/string-split
0d2c110 Add more String#split examples
68159c3 Skip filesystem encoding dependent spec
fe83324 Remove old guarded spec, implementations should be allowed to do either.
0db9d4a  Fix IO#write_nonblock spec under 2.0
40957a3 Fix IO#read_nonblock spec under 2.0
fc0d729 Add a spec covering calling #instance_eval with a proc from a method
e32825a Added specs for RARRAY_AREF.
997fc93 Added spec for IO#write_nonblock raising
45dcbd1 Test IO#read_nonblock raising EAGAINWaitReadable
400a56f Fix a typo s/refering/referring/
c76d706 Fixed Dir.pwd spec with unicode characters.
0512054 Add spec about -> lambda scoping.
f0b6cf6 Accomodate for Thread#backtrace being nil when thread is not started yet.
7462ac9 BigDecimal.new raises ArgumentError when Float is used without precision
79f43c0 do not raise when precision is passed to BigDecimal#round
26ac864 Fix line in Exception#backtrace spec.
2269430 Move the fixture class to fixtures.
d799042 Merge pull request #178 from yuki24/add-spec-for-name-error-receiver
abee55f Merge pull request #177 from yuki24/add-specs-for-name-error-name
fc420f3 Add specs for NameError#name
c127124 Add more examples for NameError#receiver
b09e8fd Simplify a spec for NameError#receiver
674b32f Speficy that hidden metaclasses stay hidden.
7b99cfc Merge pull request #179 from yuki24/use-latest-rubies
0d96eb5 Use the latest rubies on Travis
2617339 Add spec for Symbol#to_proc plus Proc#parameters => [[:rest]]
bbcb689 Mask out specs+fixtures for keyreq added in 2.1.
df59b1f Add some simple specs for Method#parameters with keyword args.
bac69ca wait for the parent to read
4960e98 Revert "wait for the parent to read" because of stall on Solaris
822aac3 NetHTTPSpecs.start_server should not use hardcoded port number.
379401f Fix and complete Thread#name spec.
9912132 [ruby-2.3 core/thread] - Add specs for Thread#name and Thread#name=
ae8ef6a Explicitly state the relation between classes since this spec is meta-meta
1a31f57 Merge pull request #173 from nobu/bug/fd-passing-tests
652d332 wait for the parent to read
f60ee1e Merge pull request #172 from nobu/feature/dig_change
e34b1a4 separate TypeError cases on dig
7526c4e Merge pull request #171 from nobu/feature/dig_change
4d25005 dig method update
2f8577d Ruby 2.3 doesn't raise error
72b2688 Specify the behavior of Date#<< with respect to the version
f8358bd Merge pull request #170 from nobu/bug/Date-minus_month-exception
1fdd93d do not mind excepction class
53f535b Merge pull request #168 from cthulhua/chunk_while
f4ae8fc [ruby-2.3 core/enumerable] - Add specs for enumerable#chunk_while
1b726f7 Merge pull request #167 from nobu/bug/fix-infection-from-range
2a8f30a Fix version to ruby_bug
67fb1f7 Merge pull request #166 from nobu/bug/fix-infection-from-range
7198825 Fix infection from Range
e1b1ba6 Use the container infrastructure on Travis CI
5cec3a3 Fix UTF-8 Encoding constant name in StringIO specs
c330bfd Fix StringIO specs file structure
e148e90 Fix StringIO#isatty describe title
1f358a4 Fix location of ObjectSpace fixtures.

git-subtree-dir: spec/ruby
git-subtree-split: 70b11404aa1f44e18b560d3d0de78ef827c1434e
2cfe47b
@eregon eregon added a commit that referenced this pull request
@eregon eregon Squashed 'spec/ruby/' changes from cfdf72f..d9a07bf
d9a07bf Module#define_method behaved differently with visibility in 2.0.0
38fdfa7 Module#prepend is private in 2.0.0
09374e5 New spec for visibility with Module#define_method and UnboundMethod
bc87a91 Fix UnboundMethod#owner specs to actually use UnboundMethod.
05f25e3 Fix spec description in Method#owner.
5a39e5a Add spec for prepend in the presence of define_method super.
42f6a39 Add example for SizedQueue#num_waiting
f27b277 Clearer name in class_variable_get spec
10a5eb4 Spec for U with malformed UTF-8 sequences.
ce8d46b Show the command when linking fails
25f9b87 Get rid of all "should_not raise_error" in language specs
6dba10a Better way to check the exact error class
a2e628f Fix bad expectation
fa031c0 Merge pull request #184 from phluid61/20160120-float-0x1p1
8bd00d6 add descriptive wrapper and tests for base case
cdd29a8 add tests for Float('0x1p1') and Float('0x1P1')
162df6a Add --disable-gems to support icc
a90ecb2 Fix Float::EPSILON spec
d8d81ef Cut to a decent amount of precision for Float::MIN and MAX
01278ce Float::MIN is 2.2250738585072e-308 in Ruby
253a399 Unify Bignum#size spec
774563a Fix typo
9011723 Use 1.9-style for Hash literals
102bf17 It seems #eval can be aliased on multiple implementations
a9a24cd Remove deviates_on behaving as the compliant specs
d0b5223 Replace hash_class by Hash
c7ca97d Use Hash literals instead of the new_hash helper
d4483ff Fix year in the history section
75ec48b Try to clarify what it is and what it is not
fec9f62 Fix wording in the history section
ad889cc Fix reference in C extension specs header
179f605 rb_str_len is not public API
6536b8b Remove old and unused version file
976c99a Fix a typo
dd6b920 Fix references in CONTRIBUTING
35f18ac Add a section about the history and RubySpec
09adfe9 Fix a few more names in the README
217fbbe Update README to reflect the new name
878ed3e Fix URLs to point the new repo name.
70b1140 Spec the default values of IO#sync for standard streams.
7753d2f Reorder Zlib deflate specs
76488f6 Fix warning in Zlib deflate spec
763d9ea Add specs for streaming in inflate processing
f484f34 Solaris 10 on x86 wrongly returns ai_pprotocol as 0
a5c0605 Remove bad spec
8b118fd Specify new behavior for Enumerable{chunk,slice_before}
5885e2b Initial spec for Queue#close and Queue#closed?
ba17b3d Spec for the new behavior of Kernel#loop
f59a862 No silent rescue in Comparable#<=> is now released behavior in 2.3
9a20b87 Treat paths with unicode characters as binary to avoid depending on the locale.
5ab735b Merge pull request #180 from ruby/string-split
0d2c110 Add more String#split examples
68159c3 Skip filesystem encoding dependent spec
fe83324 Remove old guarded spec, implementations should be allowed to do either.
0db9d4a  Fix IO#write_nonblock spec under 2.0
40957a3 Fix IO#read_nonblock spec under 2.0
fc0d729 Add a spec covering calling #instance_eval with a proc from a method
e32825a Added specs for RARRAY_AREF.
997fc93 Added spec for IO#write_nonblock raising
45dcbd1 Test IO#read_nonblock raising EAGAINWaitReadable
400a56f Fix a typo s/refering/referring/
c76d706 Fixed Dir.pwd spec with unicode characters.
0512054 Add spec about -> lambda scoping.
f0b6cf6 Accomodate for Thread#backtrace being nil when thread is not started yet.
7462ac9 BigDecimal.new raises ArgumentError when Float is used without precision
79f43c0 do not raise when precision is passed to BigDecimal#round
26ac864 Fix line in Exception#backtrace spec.
2269430 Move the fixture class to fixtures.
d799042 Merge pull request #178 from yuki24/add-spec-for-name-error-receiver
abee55f Merge pull request #177 from yuki24/add-specs-for-name-error-name
fc420f3 Add specs for NameError#name
c127124 Add more examples for NameError#receiver
b09e8fd Simplify a spec for NameError#receiver
674b32f Speficy that hidden metaclasses stay hidden.
7b99cfc Merge pull request #179 from yuki24/use-latest-rubies
0d96eb5 Use the latest rubies on Travis
2617339 Add spec for Symbol#to_proc plus Proc#parameters => [[:rest]]
bbcb689 Mask out specs+fixtures for keyreq added in 2.1.
df59b1f Add some simple specs for Method#parameters with keyword args.
bac69ca wait for the parent to read
4960e98 Revert "wait for the parent to read" because of stall on Solaris
822aac3 NetHTTPSpecs.start_server should not use hardcoded port number.
379401f Fix and complete Thread#name spec.
9912132 [ruby-2.3 core/thread] - Add specs for Thread#name and Thread#name=
ae8ef6a Explicitly state the relation between classes since this spec is meta-meta
1a31f57 Merge pull request #173 from nobu/bug/fd-passing-tests
652d332 wait for the parent to read
f60ee1e Merge pull request #172 from nobu/feature/dig_change
e34b1a4 separate TypeError cases on dig
7526c4e Merge pull request #171 from nobu/feature/dig_change
4d25005 dig method update
2f8577d Ruby 2.3 doesn't raise error
72b2688 Specify the behavior of Date#<< with respect to the version
f8358bd Merge pull request #170 from nobu/bug/Date-minus_month-exception
1fdd93d do not mind excepction class
53f535b Merge pull request #168 from cthulhua/chunk_while
f4ae8fc [ruby-2.3 core/enumerable] - Add specs for enumerable#chunk_while
1b726f7 Merge pull request #167 from nobu/bug/fix-infection-from-range
2a8f30a Fix version to ruby_bug
67fb1f7 Merge pull request #166 from nobu/bug/fix-infection-from-range
7198825 Fix infection from Range
e1b1ba6 Use the container infrastructure on Travis CI
5cec3a3 Fix UTF-8 Encoding constant name in StringIO specs
c330bfd Fix StringIO specs file structure
e148e90 Fix StringIO#isatty describe title
1f358a4 Fix location of ObjectSpace fixtures.

git-subtree-dir: spec/ruby
git-subtree-split: d9a07bfec7af8baef9daa85f2de9dcb9e18da170
69be235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 22 additions and 1 deletion.
  1. +13 −1 src/org/jruby/RubyFile.java
  2. +9 −0 test/test_file.rb
View
14 src/org/jruby/RubyFile.java
@@ -613,6 +613,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
} else {
//TODO deal with UNC names
int index = name.lastIndexOf('/');
+
if (index == -1) {
if (startsWithDriveLetterOnWindows) {
return context.getRuntime().newString(jfilename.substring(0, 2) + ".");
@@ -628,9 +629,20 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
index++;
}
+ if (jfilename.startsWith("\\\\")) {
+ index = jfilename.length();
+ String[] splitted = jfilename.split(Pattern.quote("\\"));
+ int last = splitted.length-1;
+ if (splitted[last].contains(".")) {
+ index = jfilename.lastIndexOf("\\");
+ }
+
+ }
+
result = jfilename.substring(0, index);
+
}
-
+
char endChar;
// trim trailing slashes
while (result.length() > minPathLength) {
View
9 test/test_file.rb
@@ -108,6 +108,15 @@ def test_windows_dirname
assert_equal "C:/temp", File.dirname("C:/temp/foobar.txt")
end
+ def test_windows_network_path
+
+ assert_equal("\\\\network\\share", File.dirname("\\\\network\\share\\file.bat"))
+ assert_equal("\\\\network\\share", File.dirname("\\\\network\\share"))
+ assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$\\boot.bat"))
+ assert_equal("\\\\localhost\\c$", File.dirname("\\\\localhost\\c$"))
+
+ end
+
def test_expand_path_windows
assert_equal("C:/", File.expand_path("C:/"))
assert_equal("C:/dir", File.expand_path("C:/dir"))
Something went wrong with that request. Please try again.