]> sjero.net Git - wget/commitdiff
[svn] Handle links to relative "net locations," e.g. <a href="//www.server.com/">.
authorhniksic <devnull@localhost>
Mon, 14 Jan 2002 01:56:40 +0000 (17:56 -0800)
committerhniksic <devnull@localhost>
Mon, 14 Jan 2002 01:56:40 +0000 (17:56 -0800)
src/ChangeLog
src/url.c

index 790a8527904d1cc83ebd8dcfc5757bc4cc02dabb..47272eee6e5308486b38d515ff6783b29048d028 100644 (file)
@@ -1,3 +1,8 @@
+2002-01-07  Ian Abbott <abbotti@mev.co.uk>
+
+       * url.c (uri_merge_1): Deal with "net path" relative URL (one that
+       starts with "//").
+
 2002-01-14  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * http.c (gethttp): Invalidate SOCK if get_contents encountered an
index 171f3e0a95e931a1db8fc2cf8ec8989e02294b48..7a44a8050d12710669875606b2034dace0abb401 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -1575,6 +1575,37 @@ uri_merge_1 (const char *base, const char *link, int linklength, int no_scheme)
          memcpy (constr + baselength, link, linklength);
          constr[baselength + linklength] = '\0';
        }
+      else if (linklength > 1 && *link == '/' && *(link + 1) == '/')
+       {
+         /* LINK begins with "//" and so is a net path: we need to
+            replace everything after (and including) the double slash
+            with LINK. */
+
+         /* uri_merge("foo", "//new/bar")            -> "//new/bar"      */
+         /* uri_merge("//old/foo", "//new/bar")      -> "//new/bar"      */
+         /* uri_merge("http://old/foo", "//new/bar") -> "http://new/bar" */
+
+         int span;
+         const char *slash;
+         const char *start_insert;
+
+         /* Look for first slash. */
+         slash = memchr (base, '/', end - base);
+         /* If found slash and it is a double slash, then replace
+            from this point, else default to replacing from the
+            beginning.  */
+         if (slash && *(slash + 1) == '/')
+           start_insert = slash;
+         else
+           start_insert = base;
+
+         span = start_insert - base;
+         constr = (char *)xmalloc (span + linklength + 1);
+         if (span)
+           memcpy (constr, base, span);
+         memcpy (constr + span, link, linklength);
+         constr[span + linklength] = '\0';
+       }
       else if (*link == '/')
        {
          /* LINK is an absolute path: we need to replace everything