我在PHP网站上使用HTMLPurifier我正在使用Mac上的XAMPP在本地开发和测试。该应用程序使用Doctrine2 + Codeigniter构建。
我在保存模型时在大约4个文本字段上运行HTMLPurifier。有时我这样做会收到No Data Received错误消息。检查apache日志我看到这条消息:
*** set a breakpoint in malloc_error_break to debug
httpd(60406) malloc: *** error for object 0x2af7070: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
httpd(60412) malloc: *** error for object 0x2ae0004: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
httpd(60412) malloc: *** error for object 0x2af7070: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
[Sun Oct 21 13:13:18 2012] [notice] child pid 60414 exit signal Segmentation fault (11)
如果我关闭HTMLPurifier,则不会跟踪任何错误消息。
以下是我正在使用的代码:
// ContentMedia model
public function purifyHTMLText(){
$CI =& get_instance();
$this->imageCredits = $CI->applibrary->doPurify($this->imageCredits);
$this->contentCopy = $CI->applibrary->doPurify($this->contentCopy);
$this->extraCredits = $CI->applibrary->doPurify($this->extraCredits);
$this->authors = $CI->applibrary->doPurify($this->authors);
}
// AppLibrary
public function getHTMLPurifier(){
if(!isset($htmlPurifier)){
$CI =& get_instance();
$CI->load->library('HTMLPurifier');
$config = \HTMLPurifier_Config::createDefault();
$config->set('HTML.Allowed', 'a[href],br,b,strong,em');
$config->set('HTML.DefinitionID', 'mydef');
$config->set('HTML.DefinitionRev', 1);
$config->set('Cache.DefinitionImpl', 'Serializer');
$def = $config->maybeGetRawDefinition('HTML');
$this->htmlPurifier = new \HTMLPurifier($config);
}
}
public function doPurify($text){
$this->getHTMLPurifier();
return $this->htmlPurifier->purify($text);
}