--- filter.module	2009-08-10 04:04:37.000000000 -0700
+++ filter.module.new	2009-10-19 20:53:12.000000000 -0700
@@ -770,14 +770,14 @@ function _filter_htmlcorrector($text) {
     $no_nesting = drupal_map_assoc(array('li', 'p'));
 
     // Single use tags in HTML4
-    $single_use = drupal_map_assoc(array('base', 'meta', 'link', 'hr', 'br', 'param', 'img', 'area', 'input', 'col', 'frame'));
+    $single_use = drupal_map_assoc(array('base', 'meta', 'link', 'hr', 'br', 'param', 'img', 'area', 'input', 'col', 'frame', '!--'));
   }
 
   // Properly entify angles.
-  $text = preg_replace('!<([^a-zA-Z/])!', '&lt;\1', $text);
+  $text = preg_replace('@<([^a-zA-Z/!])@', '&lt;\1', $text);
 
   // Split tags from text.
-  $split = preg_split('/<([^>]+?)>/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+  $split = preg_split('/<(!--.*?--|[^>]+?)>/s', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
   // Note: PHP ensures the array consists of alternating delimiters and literals
   // and begins and ends with a literal (inserting $null as required).
 
@@ -787,7 +787,7 @@ function _filter_htmlcorrector($text) {
   foreach ($split as $value) {
     // Process HTML tags.
     if ($tag) {
-      list($tagname) = explode(' ', strtolower($value), 2);
+      list($tagname) = preg_split('/\s/', strtolower($value), 2);
       // Closing tag
       if ($tagname{0} == '/') {
         $tagname = substr($tagname, 1);
@@ -814,7 +814,7 @@ function _filter_htmlcorrector($text) {
           array_unshift($stack, $tagname);
         }
         // Add trailing slash to single-use tags as per X(HT)ML.
-        else {
+        elseif ($tagname !== '!--') {
           $value = rtrim($value, ' /') .' /';
         }
         $output .= '<'. $value .'>';
@@ -882,7 +882,7 @@ function _filter_autop($text) {
   // We don't apply any processing to the contents of these tags to avoid messing
   // up code. We look for matched pairs and allow basic nesting. For example:
   // "processed <pre> ignored <script> ignored </script> ignored </pre> processed"
-  $chunks = preg_split('@(</?(?:pre|script|style|object)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+  $chunks = preg_split('@(<(?:!--.*?--|/?(?:pre|script|style|object)[^>]*)>)@si', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
   // Note: PHP ensures the array consists of alternating delimiters and literals
   // and begins and ends with a literal (inserting NULL as required).
   $ignore = FALSE;
