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)
This commit is contained in:
cinap_lenrek 2013-07-11 20:06:34 +02:00
parent ee67552c4b
commit 4c47ba6996
2 changed files with 29 additions and 20 deletions

View file

@ -101,9 +101,9 @@ void rdform(Hglob *g){
}
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 @@ void rdform(Hglob *g){
} 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 @@ void rdform(Hglob *g){
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 @@ void rdform(Hglob *g){
}
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,16 +257,16 @@ void rdform(Hglob *g){
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");
}
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 @@ void rdform(Hglob *g){
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);

View file

@ -717,7 +717,8 @@ void plrdhtml(char *name, int fd, Www *dst){
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 @@ void plrdhtml(char *name, int fd, Www *dst){
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 @@ void plrdhtml(char *name, int fd, Www *dst){
}
}
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 @@ void plrdhtml(char *name, int fd, Www *dst){
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 @@ void plrdhtml(char *name, int fd, Www *dst){
}
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 @@ void plrdhtml(char *name, int fd, Www *dst){
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;