pry-rails icon indicating copy to clipboard operation
pry-rails copied to clipboard

A few cases recognize-path doesn't handle.

Open ghost opened this issue 11 years ago • 9 comments

Doesn't work:

http://example.com/foo/bar (routes a 404).
foo/bar (routes as 404).

Works fine:

/foo/bar

ghost avatar Aug 06 '13 13:08 ghost

/cc @kyrylo

ghost avatar Aug 06 '13 13:08 ghost

For the URL I don't think it should try to match anything from the domain but just take the path & use that.

ghost avatar Aug 06 '13 13:08 ghost

foo/bar doesn't work by design.

http://example.com/foo/bar doesn't work because you specified the protocol. Yeah, it's not smart enough to detect whether you provided a protocol or not. It just automatically appends it. So it should be example.com/foo/bar instead.

kyrylo avatar Aug 06 '13 19:08 kyrylo

@kyrylo can pry-rails not handle the cases Rails cannot? I copy+paste from my URL all the time, and I don't consult RFCs beforehand. I think it's not hard to handle these cases, they're very easy to solve before passing to the Rails API.

ghost avatar Aug 06 '13 19:08 ghost

I'm thinking of something like this for the first case:

unless fragment.starts_with? "/"
  warn "Prepending / to #{fragment}"
  fragment.prepend "/"
end

For the second case:

fragment = URI.parse(fragment).path rescue fragment

ghost avatar Aug 06 '13 19:08 ghost

Why not? Looks good to me. I had borne in mind these possible extensions to the command when I worked on it. However, I decided to make it as simple as it can be, because I wasn't sure the patch would be accepted.

kyrylo avatar Aug 06 '13 19:08 kyrylo

@kyrylo ah I see. okay. should I make the pull request, or you? :-D I'd love for those cases to be handled because anytime I use the recongize-path command I'm copying from a browser's URL bar or somewhere like that. It'd be nice to copy+paste & it "just works".

ghost avatar Aug 06 '13 19:08 ghost

Sure, it would be cool, go for it. You're probably the most active recognize-path user :-P

kyrylo avatar Aug 06 '13 21:08 kyrylo

added to the never ending list ;-)

ghost avatar Aug 07 '13 03:08 ghost