Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Link resolution is wrong #6

Open
MadGhigno opened this issue Feb 13, 2019 · 0 comments
Open

Link resolution is wrong #6

MadGhigno opened this issue Feb 13, 2019 · 0 comments

Comments

@MadGhigno
Copy link

MadGhigno commented Feb 13, 2019

Sorry guys,
but if the purpose of this library is to help converting relative links to absolute links I have to say that it doesn't respect any of the specs in the RFC 1808 (https://www.rfc-editor.org/info/rfc1808).

Following your example:

CASE 1:

var converted = converter.convert('<img src="foo.png">', 'http://mysite.com');

result is: <img src="http://mysite.com/foo.png"> which is CORRECT

This is a very simple case but in internet you'll encounter hundreds of different cases.

CASE 2:

var converted = converter.convert('<img src="/images/foo.png">', 'http://mysite.com/context');

result is: <img src="http://mysite.com/context/images/foo.png"> which is WRONG
The RIGHT link is: <img src="http://mysite.com/images/foo.png">. The link starts with a "/" which means that you have to attach it to the domain root.

CASE 3:

var converted = converter.convert('<img src="../foo.png">', 'http://mysite.com/context');

result is: <img src="http://mysite.com/context/../foo.png"> which is WRONG
The RIGHT link is: <img src="http://mysite.com/foo.png">. The link start with "../" which means, like in the file systems, that you have to go up one level.

It's not said the the base url is the domain only, more over this class seems to just concatenate the base_url with current_url without any logic. There other hundreds of cases not covered by this library.

I find strange that no one complained about this until now.

Regards,
MadGhigno

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant