Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.368
diff -u -p -r1.368 form.inc
--- includes/form.inc	29 Aug 2009 16:30:14 -0000	1.368
+++ includes/form.inc	31 Aug 2009 18:21:25 -0000
@@ -788,7 +788,12 @@ function _form_validate($elements, &$for
       // checkboxes, can return a valid value of '0'. Instead, check the
       // length if it's a string, and the item count if it's an array.
       if ($elements['#required'] && (!count($elements['#value']) || (is_string($elements['#value']) && strlen(trim($elements['#value'])) == 0))) {
-        form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
+        // One more specialized check for file type uploads, which store their
+        // value in the $_FILES array.
+        
+        if ($elements['#type'] !== 'file' || empty($_FILES['files']['name'][$elements['#parents'][0]])) {
+          form_error($elements, t('!name field is required.', array('!name' => $elements['#title'])));
+         }
       }
 
       // Verify that the value is not longer than #maxlength.
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.43
diff -u -p -r1.43 file.test
--- modules/simpletest/tests/file.test	31 Aug 2009 05:47:34 -0000	1.43
+++ modules/simpletest/tests/file.test	31 Aug 2009 18:21:27 -0000
@@ -625,6 +625,26 @@ class FileSaveUploadTest extends FileHoo
   }
 
   /**
+   * Test the file_save_upload() function with required file field.
+   */
+  function testRequired() {
+    // Reset the hook counters to get rid of the 'load' we just called.
+    file_test_reset();
+
+    // Upload a second file.
+    $max_fid_before = db_query('SELECT MAX(fid) AS fid FROM {file}')->fetchField();
+    $image2 = current($this->drupalGetTestFiles('image'));
+    $edit = array('files[file_test_upload]' => drupal_realpath($image2->uri));
+    $this->drupalPost('file-test/upload/1', $edit, t('Submit'));
+    $this->assertResponse(200, t('Received a 200 response for posted test file.'));
+    $this->assertRaw(t('You WIN!'));
+    
+    $this->drupalPost('file-test/upload/1', array(), t('Submit'));
+    $this->assertResponse(200, t('Received a 200 response for posted test file.'));
+    $this->assertRaw(t('field is required'));
+  }
+
+  /**
    * Test renaming when uploading over a file that already exists.
    */
   function testExistingRename() {
Index: modules/simpletest/tests/file_test.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file_test.module,v
retrieving revision 1.15
diff -u -p -r1.15 file_test.module
--- modules/simpletest/tests/file_test.module	31 Aug 2009 05:47:34 -0000	1.15
+++ modules/simpletest/tests/file_test.module	31 Aug 2009 18:21:27 -0000
@@ -44,10 +44,11 @@ function file_test_stream_wrappers() {
 /**
  * Form to test file uploads.
  */
-function _file_test_form(&$form_state) {
+function _file_test_form(&$form_state, $required = FALSE) {
   $form['file_test_upload'] = array(
     '#type' => 'file',
     '#title' => t('Upload an image'),
+    '#required' => $required,
   );
   $form['file_test_replace'] = array(
     '#type' => 'select',
