[links-list] Form actions with ? in the URI

Adam Harvey matlhdam at iinet.net.au
Sun Feb 18 06:08:54 PST 2001


On Sun, 18 Feb 2001, Daniel Biddle wrote:

> Date: Sun, 18 Feb 2001 13:08:00 +0000 (UTC)
> From: Daniel Biddle <deltab at osian.net>
> To: Adam Harvey <matlhdam at iinet.net.au>
> Cc: links-list at appwatch.com
> Subject: Re: [links-list] Form actions with ? in the URI
> 
> On Sun, 18 Feb 2001, Adam Harvey wrote:
> 
> [...]
> > The patch attached retains the full action for forms that are to be
> > POSTed, but continues to strip the ? and trailing characters for GET
> > forms, since they'll have the form data sent that way and it seems a
> > bit brain-damaged to send a URI like
> > "/cgi-bin/foo.cgi?action=bar?formitem=onetwothree".
> 
> Why not simply attach the new parameters with & instead?
> "/cgi-bin/foo.cgi?action=bar&formitem=onetwothree"

Yep, that's even better. I've attached a patch which incorporates the
first patch and does that also.

Thanks Daniel :)

Adam
-------------- next part --------------
diff -ruN links-0.95/html.c links-0.95-new/html.c
--- links-0.95/html.c	Mon Jan  1 06:26:52 2001
+++ links-0.95-new/html.c	Sun Feb 18 21:41:29 2001
@@ -1040,7 +1040,6 @@
 	} else {
 		if ((ch = strchr(form->action = stracpy(format.href_base), POST_CHAR))) *ch = 0;
 	}
-	if (ch = strchr(form->action, '?')) *ch = 0;
 	if ((al = get_target(a))) {
 		form->target = al;
 	} else {
diff -ruN links-0.95/view.c links-0.95-new/view.c
--- links-0.95/view.c	Mon Jan  1 06:26:52 2001
+++ links-0.95-new/view.c	Sun Feb 18 21:49:06 2001
@@ -1294,14 +1294,18 @@
 	if (!data) goto ff;
 	if (form->method == FM_GET) {
 		if ((go = mem_alloc(strlen(form->action) + 1 + len + 1))) {
-			unsigned char *pos;
+			unsigned char *pos, *question;
 			strcpy(go, form->action);
 			if ((pos = strchr(go, '#'))) {
 				unsigned char *poss = pos;
 				pos = stracpy(pos);
 				*poss = 0;
 			}
-			if (!*go || go[strlen(go) - 1] != '?') strcat(go, "?");
+			if ((question = strchr(go, '?'))) {
+				if (question != (go + strlen(go) - 1))
+					strcat(go, "&");
+			}
+			else strcat(go, "?");
 			strcat(go, data);
 			if (pos) strcat(go, pos), mem_free(pos);
 		}


More information about the links-list mailing list