Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.21
diff -u -r1.21 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	26 Jun 2008 19:31:31 -0000	1.21
+++ modules/simpletest/drupal_web_test_case.php	26 Jun 2008 22:33:19 -0000
@@ -820,7 +820,9 @@
    * @param  $edit
    *   Field data in an assocative array. Changes the current input fields
    *   (where possible) to the values indicated. A checkbox can be set to
-   *   TRUE to be checked and FALSE to be unchecked.
+   *   TRUE to be checked and FALSE to be unchecked. Note that when a form
+   *   contains file upload fields, other fields cannot start with the '@'
+   *   character.
    * @param $submit
    *   Value of the submit button.
    * @param $options
@@ -846,10 +848,22 @@
         // We post only if we managed to handle every field in edit and the
         // submit button matches.
         if (!$edit && $submit_matches) {
-          // cURL will handle file upload for us if asked kindly.
-          foreach ($upload as $key => $file) {
-            $post[$key] = '@' . realpath($file);
+          if ($upload) {
+            // cURL handles file uploads for us
+            // but in that case we can't have a field that starts with '@'
+            foreach ($upload as $key => $file) {
+              $post[$key] = '@' . realpath($file);
+            }
           }
+          else {
+            foreach ($post as $key => $value) {
+              // Encode according to application/x-www-form-urlencoded
+              // Both names and values needs to be urlencoded, according to
+              // http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1
+              $post[$key] = urlencode($key) . '=' . urlencode($value);
+            }
+            $post = implode('&', $post);
+          }  
           $out = $this->curlExec(array(CURLOPT_URL => $action, CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $post));
           // Ensure that any changes to variables in the other thread are picked up.
           $this->refreshVariables();
