shithub: riscv

Download patch

ref: a78f5f8a3d72fc18c9bb734e066f45e9a3be5ab0
parent: 05c11fefe0c633ab061b9f69180593ed9cf073a2
author: cinap_lenrek <[email protected]>
date: Tue Jul 17 03:21:22 EDT 2012

mothra: handle relative urls in <base> tag

--- a/sys/src/cmd/mothra/mothra.h
+++ b/sys/src/cmd/mothra/mothra.h
@@ -102,5 +102,6 @@
 void geturl(char *, int, int, int);
 int urlpost(Url*, char*);
 int urlget(Url*, int);
+int urlresolve(Url *);
 char version[];
 Mouse mouse;
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -734,8 +734,12 @@
 			g.spacc++;
 			break;
 		case Tag_base:
-			if(str=pl_getattr(g.attr, "href"))
+			if(str=pl_getattr(g.attr, "href")){
+				seturl(g.dst->url, str, g.dst->url->fullname);
 				nstrcpy(g.dst->url->fullname, str, sizeof(g.dst->url->fullname));
+				/* base should be a full url, but it often isnt so have to resolve */
+				urlresolve(g.dst->url);
+			}
 			break;
 		case Tag_a:
 			if(str=pl_getattr(g.attr, "name"))
--- a/sys/src/cmd/mothra/url.c
+++ b/sys/src/cmd/mothra/url.c
@@ -151,3 +151,20 @@
 
 	return fd;
 }
+
+int
+urlresolve(Url *url)
+{
+	char buf[1024];
+	int n, fd;
+
+	if((fd = webclone(url, buf, sizeof(buf))) < 0)
+		return -1;
+	n = strlen(buf);
+	snprint(buf+n, sizeof(buf)-n, "/parsed/url");
+	readstr(buf, url->fullname, sizeof(url->fullname));
+	snprint(buf+n, sizeof(buf)-n, "/parsed/fragment");
+	readstr(buf, url->tag, sizeof(url->tag));
+	close(fd);
+	return 0;
+}