git: 9front

Download patch

ref: 16d857dace8a60143bc3824ac7b9ee5dd7328787
parent: 9132c7dfe303744c3911c3ab69f9ef78829608b3
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Thu Jul 11 16:06:34 EDT 2013

mothra: handle empty attributes (for base-tag and others...)

empty href="" attribute in base-tag causes the page to break.
while at it, handle empty attributes in other parts of the
code as well. (mostly stuff like id, name shouldnt be empty)

--- a/sys/src/cmd/mothra/forms.c
+++ b/sys/src/cmd/mothra/forms.c
@@ -101,9 +101,9 @@
 		}
 		g->form=emalloc(sizeof(Form));
 		s=pl_getattr(g->attr, "action");
-		g->form->action=strdup((s && s[0]) ? s : g->dst->url->fullname);
+		g->form->action=strdup((s && *s) ? s : g->dst->url->fullname);
 		s=pl_getattr(g->attr, "method");
-		if(s==0)
+		if(s==0 || *s==0)
 			g->form->method=GET;
 		else if(cistrcmp(s, "post")==0)
 			g->form->method=POST;
@@ -137,7 +137,7 @@
 		} else
 			f=newfield(g->form);
 		s=pl_getattr(g->attr, "name");
-		if(s==0)
+		if(s==0 || *s == 0)
 			f->name=0;
 		else
 			f->name=strdup(s);
@@ -148,12 +148,12 @@
 			f->value=strdup(s);
 		f->checked=pl_hasattr(g->attr, "checked");
 		s=pl_getattr(g->attr, "size");
-		if(s==0)
+		if(s==0 || *s==0)
 			f->size=20;
 		else
 			f->size=atoi(s);
 		s=pl_getattr(g->attr, "maxlength");
-		if(s==0)
+		if(s==0 || *s==0)
 			f->maxlength=0x3fffffff;
 		else
 			f->maxlength=atoi(s);
@@ -215,7 +215,7 @@
 		}
 		f=newfield(g->form);
 		s=pl_getattr(g->attr, "name");
-		if(s==0){
+		if(s==0 || *s==0){
 			f->name=strdup("select");
 			htmlerror(g->name, g->lineno, "select has no name=\n");
 		}
@@ -257,7 +257,7 @@
 		if(g->form==0) goto BadTag;
 		f=newfield(g->form);
 		s=pl_getattr(g->attr, "name");
-		if(s==0){
+		if(s==0 || *s==0){
 			f->name=strdup("enter text");
 			htmlerror(g->name, g->lineno, "select has no name=\n");
 		}
@@ -264,9 +264,9 @@
 		else
 			f->name=strdup(s);
 		s=pl_getattr(g->attr, "rows");
-		f->rows=s?atoi(s):8;
+		f->rows=(s && *s)?atoi(s):8;
 		s=pl_getattr(g->attr, "cols");
-		f->cols=s?atoi(s):30;
+		f->cols=(s && *s)?atoi(s):30;
 		f->type=TEXTWIN;
 		/* suck up initial text */
 		pl_htmloutput(g, g->nsp, f->name, f);
@@ -281,7 +281,7 @@
 		form->fields=0;
 		form->efields=0;
 		s=pl_getattr(g->attr, "action");
-		form->action=strdup((s && s[0]) ? s : g->dst->url->fullname);
+		form->action=strdup((s && *s) ? s : g->dst->url->fullname);
 		form->method=GET;
 		form->fields=0;
 		f=newfield(form);
--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -717,7 +717,8 @@
 			pl_pushstate(&g, g.tag);
 			break;
 		}
-		if(str=pl_getattr(g.attr, "id")){
+		str=pl_getattr(g.attr, "id");
+		if(str && *str){
 			char swap[NNAME];
 
 			nstrcpy(swap, g.state->name, sizeof(swap));
@@ -733,7 +734,8 @@
 		case Tag_end:	/* unrecognized start tag */
 			break;
 		case Tag_img:
-			if(str=pl_getattr(g.attr, "src"))
+			str=pl_getattr(g.attr, "src");
+			if(str && *str)
 				nstrcpy(g.state->image, str, sizeof(g.state->image));
 			else {
 				Pair *a;
@@ -754,12 +756,14 @@
 				}
 			}
 			g.state->ismap=pl_hasattr(g.attr, "ismap");
-			if(str=pl_getattr(g.attr, "width"))
+			str=pl_getattr(g.attr, "width");
+			if(str && *str)
 				g.state->width=strtolength(&g, HORIZ, str);
-			if(str=pl_getattr(g.attr, "height"))
+			str=pl_getattr(g.attr, "height");
+			if(str && *str)
 				g.state->height=strtolength(&g, VERT, str);
 			str=pl_getattr(g.attr, "alt");
-			if(str==0){
+			if(str==0 || *str == 0){
 				if(g.state->image[0])
 					str=g.state->image;
 				else
@@ -789,7 +793,8 @@
 			g.spacc++;
 			break;
 		case Tag_base:
-			if(str=pl_getattr(g.attr, "href")){
+			str=pl_getattr(g.attr, "href");
+			if(str && *str){
 				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 */
@@ -797,10 +802,12 @@
 			}
 			break;
 		case Tag_a:
-			if(str=pl_getattr(g.attr, "name"))
+			str=pl_getattr(g.attr, "name");
+			if(str && *str)
 				nstrcpy(g.state->name, str, sizeof(g.state->name));
 			pl_htmloutput(&g, 0, "", 0);
-			if(str=pl_getattr(g.attr, "href"))
+			str=pl_getattr(g.attr, "href");
+			if(str && *str)
 				nstrcpy(g.state->link, str, sizeof(g.state->link));
 			break;
 		case Tag_meta:
@@ -829,9 +836,11 @@
 		case Tag_iframe:
 			snprint(buf, sizeof(buf), "[%s: ", tag[g.tag].name);
 			pl_htmloutput(&g, 0, buf, 0);
-			if(str=pl_getattr(g.attr, "src"))
+			str=pl_getattr(g.attr, "src");
+			if(str && *str)
 				nstrcpy(g.state->link, str, sizeof(g.state->link));
-			if(str=pl_getattr(g.attr, "name"))
+			str=pl_getattr(g.attr, "name");
+			if(str && *str)
 				nstrcpy(g.state->name, str, sizeof(g.state->name));
 			else
 				str = g.state->link;
--