Skip to content

Commit eac7ca3

Browse files
committed
7802 Filter script tags from HTML of CMS pages during indexing
The tags themselves have been removed before, but not there content.
1 parent 06a6992 commit eac7ca3

File tree

1 file changed

+14
-2
lines changed
  • src/app/code/community/IntegerNet/Solr/Model/Bridge

1 file changed

+14
-2
lines changed

src/app/code/community/IntegerNet/Solr/Model/Bridge/Page.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public function getTitle()
5959
public function getContent()
6060
{
6161
if (is_null($this->_content)) {
62-
$this->_content = Mage::helper('cms')->getPageTemplateProcessor()->filter($this->_page->getData('content'));
62+
$this->_content = $this->filterHtml(Mage::helper('cms')->getPageTemplateProcessor()->filter($this->_page->getData('content')));
6363
}
6464
return $this->_content;
6565
}
6666

6767
public function getAbstract()
6868
{
69-
$content = trim(strip_tags(html_entity_decode(str_replace(array("\r", "\n", "\t"), ' ', $this->getContent()))));
69+
$content = trim($this->filterHtml(html_entity_decode(str_replace(array("\r", "\n", "\t"), ' ', $this->getContent()))));
7070
if (strlen($content) > self::ABSTRACT_MAX_LENGTH) {
7171
$content = substr($content, 0, self::ABSTRACT_MAX_LENGTH) . '…';
7272
}
@@ -130,4 +130,16 @@ public function __call($method, $args)
130130
{
131131
return call_user_func_array(array($this->_page, $method), $args);
132132
}
133+
134+
/**
135+
* Remove script tags (including its content) and other tags (keeping their content)
136+
*
137+
* @param string $html
138+
* @return string
139+
*/
140+
private function filterHtml($html)
141+
{
142+
$html = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
143+
return strip_tags($html);
144+
}
133145
}

0 commit comments

Comments
 (0)