I am currently developing an HTML parser and I came to one specific website that is not properly coded in terms of urls. On the main page ("http://example.com/a/b"), I have some links starting with "a/b" without the initial "/". Ruby URI works correctly as per my understanding of relative paths:
uri = URI("http://example.com/a/b")
(uri + "a/b").to_s
==> http://example.com/a/a/b
However, the behavior seems to be different in a browser such as Firefox or Chrome, as the page is directed to http://example.com/a/b (which works by the way).
Have you seen this before and what would you suggest to have the same behavior in Ruby than in Web browsers?
I think uri + 'a/b' is simply doing a string concatenation.
What I would suggest is to try this:
File.join('http://www.example.com', 'a/b')
File.join supports this kind of operation :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With