Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.328
diff -u -9 -p -r1.328 filter.module
--- modules/filter/filter.module	24 Apr 2010 14:53:59 -0000	1.328
+++ modules/filter/filter.module	29 Apr 2010 19:54:17 -0000
@@ -1438,35 +1438,35 @@ function _filter_autop($text) {
         }
       }
       // Only allow a matching tag to close it.
       elseif (!$open && $ignoretag == $tag) {
         $ignore = FALSE;
         $ignoretag = '';
       }
     }
     elseif (!$ignore) {
-      $chunk = preg_replace('|\n*$|', '', $chunk) . "\n\n"; // just to make things a little easier, pad the end
+      $chunk = preg_replace('`\n*$`', '', $chunk) . "\n\n"; // just to make things a little easier, pad the end
-      $chunk = preg_replace('|<br />\s*<br />|', "\n\n", $chunk);
+      $chunk = preg_replace('`<br ?/?>\s*<br ?/?>`i', "\n\n", $chunk);
-      $chunk = preg_replace('!(<' . $block . '[^>]*>)!', "\n$1", $chunk); // Space things out a little
+      $chunk = preg_replace('`(<' . $block . '[^>]*>)`i', "\n$1", $chunk); // Space things out a little
-      $chunk = preg_replace('!(</' . $block . '>)!', "$1\n\n", $chunk); // Space things out a little
+      $chunk = preg_replace('`(</' . $block . '>)`i', "$1\n\n", $chunk); // Space things out a little
-      $chunk = preg_replace("/\n\n+/", "\n\n", $chunk); // take care of duplicates
+      $chunk = preg_replace('`\n\n+`', "\n\n", $chunk); // take care of duplicates
-      $chunk = preg_replace('/^\n|\n\s*\n$/', '', $chunk);
+      $chunk = preg_replace('`^\n|\n\s*\n$`', '', $chunk);
-      $chunk = '<p>' . preg_replace('/\n\s*\n\n?(.)/', "</p>\n<p>$1", $chunk) . "</p>\n"; // make paragraphs, including one at the end
+      $chunk = '<p>' . preg_replace('`\n\s*\n\n?(.)`', "</p>\n<p>$1", $chunk) . "</p>\n"; // make paragraphs, including one at the end
-      $chunk = preg_replace("|<p>(<li.+?)</p>|", "$1", $chunk); // problem with nested lists
+      $chunk = preg_replace('`<p>(<li.+?)</p>`i', '$1', $chunk); // problem with nested lists
-      $chunk = preg_replace('|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $chunk);
+      $chunk = preg_replace('`<p><blockquote([^>]*)>`i', '<blockquote$1><p>', $chunk);
       $chunk = str_replace('</blockquote></p>', '</p></blockquote>', $chunk);
-      $chunk = preg_replace('|<p>\s*</p>\n?|', '', $chunk); // under certain strange conditions it could create a P of entirely whitespace
+      $chunk = preg_replace('`<p>\s*</p>\n?`i', '', $chunk); // under certain strange conditions it could create a P of entirely whitespace
-      $chunk = preg_replace('!<p>\s*(</?' . $block . '[^>]*>)!', "$1", $chunk);
+      $chunk = preg_replace('`<p>\s*(</?' . $block . '[^>]*>)`i', '$1', $chunk);
-      $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*</p>!', "$1", $chunk);
+      $chunk = preg_replace('`(</?' . $block . '[^>]*>)\s*</p>`i', '$1', $chunk);
-      $chunk = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $chunk); // make line breaks
+      $chunk = preg_replace('`(?<!<br />|<br/>|<br>)\s*\n`i', "<br />\n", $chunk); // make line breaks
-      $chunk = preg_replace('!(</?' . $block . '[^>]*>)\s*<br />!', "$1", $chunk);
+      $chunk = preg_replace('`(</?' . $block . '[^>]*>)\s*<br ?/?>`i', '$1', $chunk);
-      $chunk = preg_replace('!<br />(\s*</?(?:p|li|div|th|pre|td|ul|ol)>)!', '$1', $chunk);
+      $chunk = preg_replace('`<br ?/?>(\s*</?(?:p|li|div|th|pre|td|ul|ol)>)`i', '$1', $chunk);
-      $chunk = preg_replace('/&([^#])(?![A-Za-z0-9]{1,8};)/', '&amp;$1', $chunk);
+      $chunk = preg_replace('`&([^#])(?![A-Za-z0-9]{1,8};)`', '&amp;$1', $chunk);
     }
     $output .= $chunk;
   }
   return $output;
 }
 
 /**
  * Filter tips callback for auto-paragraph filter.
  */
Index: modules/filter/filter.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v
retrieving revision 1.66
diff -u -9 -p -r1.66 filter.test
--- modules/filter/filter.test	11 Apr 2010 18:33:44 -0000	1.66
+++ modules/filter/filter.test	29 Apr 2010 22:58:39 -0000
@@ -667,18 +667,24 @@ class FilterUnitTestCase extends DrupalU
     $f = _filter_autop('<p><div>  </div></p>');
     $this->assertEqual(substr_count($f, '<p>'), substr_count($f, '</p>'), t('Make sure line breaking produces matching paragraph tags.'));
 
     $f = _filter_autop('<div><p>  </p></div>');
     $this->assertEqual(substr_count($f, '<p>'), substr_count($f, '</p>'), t('Make sure line breaking produces matching paragraph tags.'));
 
     $f = _filter_autop('<blockquote><pre>aaa</pre></blockquote>');
     $this->assertEqual(substr_count($f, '<p>'), substr_count($f, '</p>'), t('Make sure line breaking produces matching paragraph tags.'));
 
+    $f = _filter_autop('<P>foo</P>');
+    $this->assertEqual(trim($f), '<P>foo</P>', t('Make sure line breaking supports upper-case tag names.').$f);
+
+    $f = _filter_autop('<TABLE><TR><TD>foo</TD><TD>aaa<BR>\nbbb</TD></TR></TABLE>');
+    $this->assertEqual(preg_replace('/\s/', '', $f), preg_replace('/\s/', '', $f), t('Make sure line breaking supports upper-case tag names.'));
+
     $limit = max(ini_get('pcre.backtrack_limit'), ini_get('pcre.recursion_limit'));
     $f = _filter_autop($this->randomName($limit));
     $this->assertNotEqual($f, '', t('Make sure line breaking can process long strings.'));
   }
 
   /**
    * Test limiting allowed tags, XSS prevention and adding 'nofollow' to links.
    *
    * XSS tests assume that script is disallowed on default and src is allowed
