git: 9front

Download patch

ref: c3f6c125994e5e21d0913cc75126f57c06d254c7
parent: 11a993222934bcf02350d8357aefb4f7e19172bc
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sun Jun 24 04:36:42 EDT 2012

mothra/uhtml: properly handle quoting in tags

--- a/sys/src/cmd/mothra/rdhtml.c
+++ b/sys/src/cmd/mothra/rdhtml.c
@@ -474,13 +474,23 @@
  */
 int pl_gettag(Hglob *g){
 	char *tokp;
-	int c;
+	int c, q;
 	tokp=g->token;
 	if((c=pl_nextc(g))=='!' || c=='?')
 		return pl_getcomment(g);
 	pl_putback(g, c);
-	while((c=pl_nextc(g))!=ETAG && c!=EOF)
-		if(tokp < &g->token[NTOKEN-UTFmax-1]) tokp += lrunetochar(tokp, c);
+	q = 0;
+	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';
 	if(c==EOF) htmlerror(g->name, g->lineno, "EOF in tag");
 	pl_tagparse(g, g->token);
--- a/sys/src/cmd/uhtml.c
+++ b/sys/src/cmd/uhtml.c
@@ -47,7 +47,7 @@
 void
 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;
 	Rune r;
 
@@ -96,12 +96,24 @@
 		do {
 			if((s = strchr(s, '<')) == nil)
 				break;
-			g = s;
-			if((e = strchr(++s, '>')) == nil)
-				e = buf+nbuf;
+			q = 0;
+			g = ++s;
+			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;
 			*e = 0;
-			if((a = attr(s, "encoding")) || (a = attr(s, "charset"))){
+			if((a = attr(g, "encoding")) || (a = attr(g, "charset"))){
 				cset = a;
 				*e = t;
 				break;
--