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

Pathname#relative_path_from failing when there is a '!' character in the path #3392

Closed
hading opened this Issue Oct 12, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@hading
Copy link

commented Oct 12, 2015

For jruby-9.0.1.0 (discovered on 9.0.0.0). I don't know if there are other characters that trigger this.

E.g.
jruby-9.0.1.0 :001 > require 'pathname'
=> true
jruby-9.0.1.0 :002 > x = "joe"
=> "joe"
jruby-9.0.1.0 :003 > y = "joe/pete!/bob"
=> "joe/pete!/bob"
jruby-9.0.1.0 :004 > Pathname.new(y).relative_path_from(Pathname.new(x))
ArgumentError: different prefix: "joe/pete!/" and "joe"
from /Users/hding2/.rvm/rubies/jruby-9.0.1.0/lib/ruby/stdlib/pathname.rb:508:in relative_path_from' from (irb):4:in'
from org/jruby/RubyKernel.java:978:in eval' from org/jruby/RubyKernel.java:1291:inloop'
from org/jruby/RubyKernel.java:1098:in catch' from org/jruby/RubyKernel.java:1098:incatch'
from /Users/hding2/.rvm/rubies/jruby-9.0.1.0/bin/irb:13:in `'

In ruby-2.2.3:
2.2.3 :001 > require 'pathname'
=> true
2.2.3 :002 > x = "joe"
=> "joe"
2.2.3 :003 > y = "joe/pete!/bob"
=> "joe/pete!/bob"
2.2.3 :004 > Pathname.new(y).relative_path_from(Pathname.new(x))
=> #Pathname:pete!/bob

@mkristian

This comment has been minimized.

Copy link
Member

commented Oct 13, 2015

this is true and it is onaly a problem with an ! at the end of the name. there are quite some places where we discover jar urls like

my.jar!/script.rb
file:my.jar!/script.rb
jar:file:my.jar!/script.rb

by looking for !/
since this feature is more a legacy feature I think it can be more restrictive by looking for .jar!/ instead

@hading

This comment has been minimized.

Copy link
Author

commented Oct 13, 2015

To give more detail, I found the problem in the context of digital preservation in a library. We get sets of files with all kinds of bizarre (to me) naming convention/directory structures coming from our various units. In particular our archive unit is likely to get weird stuff and want to preserve it as is. I think the particular case I found was something like ../../PLUS!/../...

So if a general solution is possible I'd certainly be appreciative, but I do bear in mind that I wouldn't be the one doing it.

Also I'm a little confused by the idea that it is a legacy feature - is there equivalent functionality for Pathname#relative_path_from elsewhere in ruby or the stdlib?

Thanks,
Howard

@mkristian

This comment has been minimized.

Copy link
Member

commented Oct 13, 2015

the legacy feature is to allow such jar like paths with file: or jar:file: or no protocol prefix at all. I will have a look and please feel free to report any other pathname/directory-name which gives you problems.

@hading

This comment has been minimized.

Copy link
Author

commented Oct 13, 2015

Thanks. I was getting another (different) error that went away when I hacked around this issue, but I'll see if I can reproduce it and see if it is a jruby issue or not.

@hading

This comment has been minimized.

Copy link
Author

commented Oct 13, 2015

I found the other problem. Let me know if you'd like me to open another ticket for it. This time it's when the path involves some unicode characters:

jruby-9.0.0.0 :007 > x = "joe"
=> "joe"
jruby-9.0.0.0 :008 > y = "joe/⸀䐀攀氀攀琀攀䴀攀/fred"
=> "joe/⸀䐀攀氀攀琀攀䴀攀/fred"
jruby-9.0.0.0 :009 > Pathname.new(y).relative_path_from(Pathname.new(x))
TypeError: no implicit conversion from nil to integer
from org/jruby/RubyString.java:2870:in []' from /services/medusa/.rvm/rubies/jruby-9.0.0.0/lib/ruby/stdlib/pathname.rb:48:inchop_basename'
from /services/medusa/.rvm/rubies/jruby-9.0.0.0/lib/ruby/stdlib/pathname.rb:113:in cleanpath_aggressive' from /services/medusa/.rvm/rubies/jruby-9.0.0.0/lib/ruby/stdlib/pathname.rb:91:incleanpath'
from /services/medusa/.rvm/rubies/jruby-9.0.0.0/lib/ruby/stdlib/pathname.rb:493:in relative_path_from' from (irb):9:in'
from org/jruby/RubyKernel.java:979:in eval' from org/jruby/RubyKernel.java:1292:inloop'
from org/jruby/RubyKernel.java:1099:in catch' from org/jruby/RubyKernel.java:1099:incatch'
from /services/medusa/.rvm/rubies/jruby-9.0.0.0/bin/irb:13:in `'

Here's the MRI version, which works:

2.2.3 :006 > x = "joe"
=> "joe"
2.2.3 :007 > y = "joe/⸀䐀攀氀攀琀攀䴀攀/fred"
=> "joe/⸀䐀攀氀攀琀攀䴀攀/fred"
2.2.3 :008 > Pathname.new(y).relative_path_from(Pathname.new(x))
=> #Pathname:⸀䐀攀氀攀琀攀䴀攀/fred

@mkristian

This comment has been minimized.

Copy link
Member

commented Oct 14, 2015

please file a second issue since it is really something else going wrong ;)
thanx

@hading

This comment has been minimized.

Copy link
Author

commented Oct 14, 2015

Okay, filed as issue #3396.

@kares kares added this to the JRuby 1.7.23 milestone Oct 30, 2015

@mkristian mkristian closed this in 2a2c6f8 Nov 17, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.