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

Comments

Projects
None yet
4 participants
@dlovellrw

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Aug 29, 2016

Member

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?

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?

jsyeo added a commit to jsyeo/jruby that referenced this issue Sep 23, 2016

@enebo enebo closed this in #4177 Nov 6, 2016

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