Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.dirname interprets backslashes as path separators on Mac OS X #4116

Closed
dlovellrw opened this issue Aug 25, 2016 · 1 comment · Fixed by #4177
Closed

File.dirname interprets backslashes as path separators on Mac OS X #4116

dlovellrw opened this issue Aug 25, 2016 · 1 comment · Fixed by #4177

Comments

@dlovellrw
Copy link

Environment

~/> ruby -v
jruby 1.7.21 (1.9.3p551) 2015-07-07 a741a82 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_31-b13 +jit [darwin-x86_64]
~> uname -a
Darwin 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

Expected Behavior

~> ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin15.6.0]
~> irb
irb(main):001:0> path = 'this/path/has/filename\that\contains\backslashes'
=> "this/path/has/filename\\that\\contains\\backslashes"
irb(main):002:0> File.dirname path
=> "this/path/has"
irb(main):003:0>
~> ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
~> irb
irb(main):001:0> path = 'this/path/has/filename\that\contains\backslashes'
=> "this/path/has/filename\\that\\contains\\backslashes"
irb(main):002:0> File.dirname path
=> "this/path/has"
irb(main):003:0>

Actual Behavior

~> ruby -v
jruby 1.7.21 (1.9.3p551) 2015-07-07 a741a82 on Java HotSpot(TM) 64-Bit Server VM 1.8.0_31-b13 +jit [darwin-x86_64]
~> irb
irb(main):001:0> path = 'this/path/has/filename\that\contains\backslashes'
=> "this/path/has/filename\\that\\contains\\backslashes"
irb(main):002:0> File.dirname path
=> "this/path/has/filename\\that\\contains"
irb(main):003:0>
~> ruby -v
jruby 9.1.2.0 (2.3.0) 2016-05-26 7357c8f Java HotSpot(TM) 64-Bit Server VM 25.31-b07 on 1.8.0_31-b13 +jit [darwin-x86_64]
~> irb
irb(main):001:0>  path = 'this/path/has/filename\that\contains\backslashes'
=> "this/path/has/filename\\that\\contains\\backslashes"
irb(main):002:0>  File.dirname path
=> "this/path/has/filename\\that\\contains"
irb(main):003:0>

Additional Information

The code in RubyFile.java uses hard-coded path separator values, e.g. line 724 if (endChar == '/' || endChar == '\\') {, rather than system dependent constants, such as Java File.separator.

@kares kares added this to the JRuby 1.7.26 milestone Aug 26, 2016
@enebo enebo modified the milestones: JRuby 1.7.26, JRuby 1.7.27 Aug 26, 2016
@headius
Copy link
Member

headius commented Aug 29, 2016

Shouldn't be a hard one to write a patch for...only use \ on platforms where that's the path separator. Anyone care to try a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants