commit 163a5e13b584ecf391a6ec3578771e32ccff1829
Author: pwolanin <pwolanin@49851.no-reply.drupal.org>
Date:   Sat Jun 18 23:44:27 2011 -0400

    Issue #1150174 by mr.andrey, pwolanin: Strip content of script and similar tags when indexing.

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 2af9c4c..77e5e30 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,7 @@ Apache Solr integration 7.x-1.x-xxxx, xxxx-xx-xx
 
 Apache Solr integration 7.x-1.0-xxxx, 2011-xx-xx
 ------------------------------
+#1150174 by mr.andrey, pwolanin: Strip content of script and similar tags when indexing.
 #1183742 by MrHaroldA, pwolanin: Index all numeric field API fields by default.
 #1188614 by ASupinski: Expand Hook_Hook_Info to include other hooks.
 
diff --git a/apachesolr.module b/apachesolr.module
index c1086d7..6dc345a 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -1647,6 +1647,8 @@ function apachesolr_entity_fields($entity_type = 'node') {
  * Strip html tags and also control characters that cause Jetty/Solr to fail.
  */
 function apachesolr_clean_text($text) {
+  // Remove invisible content.
+  $text = preg_replace('@<(applet|audio|canvas|command|embed|iframe|map|menu|noembed|noframes|noscript|script|style|svg|video)[^>]*>.*</\1>@siU', ' ', $text);
   // Add spaces before stripping tags to avoid running words together.
   $text = filter_xss(str_replace(array('<', '>'), array(' <', '> '), $text), array());
   // Decode entities and then make safe any < or > characters.
diff --git a/tests/solr_base_query.test b/tests/solr_base_query.test
index a420e52..bcee0a6 100644
--- a/tests/solr_base_query.test
+++ b/tests/solr_base_query.test
@@ -3,6 +3,68 @@
 /**
  * Unit tests for query object methods.
  */
+class SolrIndexHelperTests extends DrupalUnitTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Indexing helper functionality',
+      'description' => 'Tests indexing helper methods individually.',
+      'group' => 'ApacheSolr',
+    );
+  }
+
+  protected function setUp() {
+    parent::setUp();
+    $this->script_content = <<<EOF
+<p>GOOD_CONTENT</p>
+<script type="text/javascript" >
+$(document).ready(function(){
+  $('.accordion_teachers').accordion({ collapsible:true, autoHeight:false });
+});
+</script>
+EOF;
+
+    $this->embed_content = <<<EOF
+<p>GOOD_CONTENT</p>
+<object width="425" height="349"><param name="movie" value="http://www.youtube.com/v/8Vmnq5dBF7Y?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/8Vmnq5dBF7Y?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="425" height="349" allowscriptaccess="always" allowfullscreen="true"></embed></object>
+OTHER_CONTENT
+EOF;
+    $this->iframe_content = <<<EOF
+<iframe width="425" height="349" src="http://www.youtube.com/embed/8Vmnq5dBF7Y" frameborder="0" allowfullscreen></iframe>
+<p><a href="#">GOOD_CONTENT</a></p><iframe></iframe>
+EOF;
+  }
+
+  /**
+   * Test ordering of parsed filter positions.
+   *
+   * Regression test for http://drupal.org/node/891962
+   */
+  function testContentFilters() {
+    module_load_include('inc', 'apachesolr', 'apachesolr.index');
+    $cleaned = apachesolr_clean_text($this->script_content);
+    $this->assertFalse(strpos($cleaned, 'script'), 'Script tags removed');
+    $this->assertFalse(strpos($cleaned, 'accordion_teachers'), 'Script tags conent removed');
+    $this->assertTrue(strpos(trim($cleaned), 'GOOD_CONTENT') === 0, 'Real content retained');
+
+    $cleaned = apachesolr_clean_text($this->embed_content);
+    $this->assertFalse(strpos($cleaned, 'object'), 'object tags removed');
+    $this->assertFalse(strpos($cleaned, 'embed'), 'embed tags removed');
+    $this->assertFalse(strpos($cleaned, '8Vmnq5dBF7Y'), 'object tags conent removed');
+    $this->assertFalse(strpos($cleaned, 'shockwave-flash'), 'embed tags conent removed');
+    $this->assertTrue(strpos(trim($cleaned), 'GOOD_CONTENT') === 0, 'Real content retained');
+    $this->assertTrue(strpos($cleaned, 'OTHER_CONTENT') > 0, 'Other content retained');
+
+    $cleaned = apachesolr_clean_text($this->iframe_content);
+    $this->assertFalse(strpos($cleaned, 'iframe'), 'iframe tags removed');
+    $this->assertFalse(strpos($cleaned, '8Vmnq5dBF7Y'), 'iframe tags conent removed');
+    $this->assertTrue(strpos(trim($cleaned), 'GOOD_CONTENT') === 0, 'Real content retained');
+  }
+
+}
+
+/**
+ * Unit tests for query object methods.
+ */
 class SolrBaseQueryTests extends DrupalUnitTestCase {
   public static function getInfo() {
     return array(
