Reputation: 89203
Some of my users are creating links that look like
<a href='http:/some_local_path'>whatever</a>
I've noticed that Firefox interprets this as
<a href='/some_local_path'>whatever</a>
Can I count on this occurring in all browsers? Or should I remove the http:/
s myself?
Upvotes: 1
Views: 143
Reputation: 375504
This is an unusual URL, but is not invalid. The URL spec says that omitted components are defaulted from the base url, which can be provided explicitly in a <base>
tag, or absent that, the current URL of the page.
When a browser sees /some_local_path
, it is missing a scheme and a host, so it takes them from the base url. When your users put http:/some_local_path
, it has an explicit scheme, but is missing a host, so the host defaults to the base url. If your page is an http: page, then the two URLs will be interpreted identically.
All that said, those URLs are almost certainly not what your users intended. You'll be helping them if you point out their error.
Upvotes: 4
Reputation: 730
It's always best to validate data entered by users. Inevitably, you'll get something unexpected.
Upvotes: 1