mothra/uhtml: properly handle quoting in tags

front
cinap_lenrek 2012-06-24 08:36:42 +02:00
parent f0b471efb9
commit f4480d1517
2 changed files with 30 additions and 8 deletions

View File

@ -474,13 +474,23 @@ int lrunetochar(char *p, int v)
*/ */
int pl_gettag(Hglob *g){ int pl_gettag(Hglob *g){
char *tokp; char *tokp;
int c; int c, q;
tokp=g->token; tokp=g->token;
if((c=pl_nextc(g))=='!' || c=='?') if((c=pl_nextc(g))=='!' || c=='?')
return pl_getcomment(g); return pl_getcomment(g);
pl_putback(g, c); pl_putback(g, c);
while((c=pl_nextc(g))!=ETAG && c!=EOF) q = 0;
if(tokp < &g->token[NTOKEN-UTFmax-1]) tokp += lrunetochar(tokp, c); while((c=pl_nextc(g))!=EOF){
if(c == '\'' || c == '"'){
if(q == 0)
q = c;
else if(q == c)
q = 0;
} else if(c == ETAG && q == 0)
break;
if(tokp < &g->token[NTOKEN-UTFmax-1])
tokp += lrunetochar(tokp, c);
}
*tokp='\0'; *tokp='\0';
if(c==EOF) htmlerror(g->name, g->lineno, "EOF in tag"); if(c==EOF) htmlerror(g->name, g->lineno, "EOF in tag");
pl_tagparse(g, g->token); pl_tagparse(g, g->token);

View File

@ -47,7 +47,7 @@ attr(char *s, char *a)
void void
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int n, pfd[2], pflag = 0; int n, q, pfd[2], pflag = 0;
char *arg[4], *s, *e, *p, *g, *a, t; char *arg[4], *s, *e, *p, *g, *a, t;
Rune r; Rune r;
@ -96,12 +96,24 @@ main(int argc, char *argv[])
do { do {
if((s = strchr(s, '<')) == nil) if((s = strchr(s, '<')) == nil)
break; break;
g = s; q = 0;
if((e = strchr(++s, '>')) == nil) g = ++s;
e = buf+nbuf; e = buf+nbuf;
while(s < e){
if(*s == '\'' || *s == '"'){
if(q == 0)
q = *s;
else if(q == *s)
q = 0;
} else if(*s == '>' && q == 0){
e = s;
break;
}
s++;
}
t = *e; t = *e;
*e = 0; *e = 0;
if((a = attr(s, "encoding")) || (a = attr(s, "charset"))){ if((a = attr(g, "encoding")) || (a = attr(g, "charset"))){
cset = a; cset = a;
*e = t; *e = t;
break; break;