sorensen / absolutify

Replace relative URLs with absolute in a given HTML string.
MIT License
22 stars 6 forks source link

Valid targets #6

Open pex opened 8 years ago

pex commented 8 years ago

Currently the following strings won't be changed corresponding to the tests:

from test.js:

  // Non-changing string, should not get replaced
  var ok = ''
    + '<img src="www.foo.com" />'
    + '<img src="google.com" />'
    + '<img src="http://www.bar.com" />'
    + '<img src="//baz.com" />'

Though I think targets without protocol (or //) are not valid URLs and should pass for being relative paths (in this test case this applies to www.foo.com and google.com). AFAIK most browsers consider such targets as relative URLs, too.

sorensen commented 8 years ago

@pex Good catch, www.foo.com and google.com should be treated as relative, the // URL is valid though.

sorensen commented 8 years ago

@pex Just following up, I'm still working on this, the primary issue I'm running into is that there doesn't seem to be a way to normalize if a url target begins with / or not.

For example: html <a href="/some-article">Article</a> <a href="some-article">Article</a>

The only workaround I can currently think of is to run a final search/replace to convert any inputUrl// to inputUrl/

Sorry for the delay on this, edge cases are giving me some grief.

pex commented 8 years ago

Hej @sorensen I'm already glad you follow this up! Thanks for your help.

sorensen commented 7 years ago

@pex So I apparently forgot to commit any code changes for this, but I think I have a working solution for you. Would you mind checking out the target-improvement branch and verifying?