diff src/c/urweb.c @ 1788:f57983ba2a36

Get regular forms working again
author Adam Chlipala <adam@chlipala.net>
date Sat, 21 Jul 2012 15:34:07 -0400
parents 69daa6d70299
children 3d922a28370b
line wrap: on
line diff
--- a/src/c/urweb.c	Sat Jul 21 15:16:57 2012 -0400
+++ b/src/c/urweb.c	Sat Jul 21 15:34:07 2012 -0400
@@ -4100,29 +4100,28 @@
 }
 
 uw_Basis_postField *uw_Basis_firstFormField(uw_context ctx, uw_Basis_string s) {
-  char *amp, *eq, *unurl, *copy;
+  char *unurl;
   uw_Basis_postField *f;
 
-  if (s[0] == 0)
+  if (!ctx->hasPostBody)
+    uw_error(ctx, FATAL, "firstFormField called when there is no POST body");
+
+  if (s < ctx->postBody.data || s >= ctx->postBody.data + ctx->postBody.len)
     return NULL;
 
-  amp = strchr(s, '&');
-  copy = uw_malloc(ctx, amp ? amp - s + 1 : strlen(s) + 1);
-  if (amp) {
-    strncpy(copy, s, amp - s);
-    copy[amp - s] = 0;
-  } else
-    strcpy(copy, s);
-
-  eq = strchr(copy, '=');
-  if (eq)
-    *eq++ = 0;
-
   f = uw_malloc(ctx, sizeof(uw_Basis_postField));
-  unurl = copy;
+  unurl = s;
   f->name = uw_Basis_unurlifyString(ctx, &unurl);
-  f->value = eq ? (unurl = eq, uw_Basis_unurlifyString(ctx, &unurl)) : "";
-  f->remaining = amp ? amp+1 : "";
+  s = strchr(s, 0);
+  if (!s)
+    uw_error(ctx, FATAL, "firstFormField: Missing null terminator");
+  ++s;
+  unurl = s;
+  f->value = uw_Basis_unurlifyString(ctx, &unurl);
+  s = strchr(s, 0);
+  if (!s)
+    uw_error(ctx, FATAL, "firstFormField: Missing null terminator");
+  f->remaining = s+1;
 
   return f;
 }