Merge pull request #3279 from Icinga/bugfix/transform-escaped-control-characters-in-html-plugin-output-2846

Transform escaped control characters in html plugin output
This commit is contained in:
Johannes Meyer 2018-01-17 13:05:29 +01:00 committed by GitHub
commit 99c6ac5b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 3 deletions

View File

@ -51,6 +51,30 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
'@@@@@@', '@@@@@@',
); );
/**
* Patterns to be replaced in html plugin output
*
* @var array
*/
protected static $htmlPatterns = array(
'~\\\n~',
'~\\\t~',
'~\\\n\\\n~',
'~<table~'
);
/**
* Replacements for $htmlPatterns
*
* @var array
*/
protected static $htmlReplacements = array(
"\n",
"\t",
"\n",
'<table style="font-size: 0.75em"'
);
/** /**
* Render plugin output * Render plugin output
* *
@ -68,8 +92,8 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
if (preg_match('~<[^>]*["/\'][^>]*>~', $output)) { if (preg_match('~<[^>]*["/\'][^>]*>~', $output)) {
// HTML // HTML
$output = preg_replace( $output = preg_replace(
'~<table~', self::$htmlPatterns,
'<table style="font-size: 0.75em"', self::$htmlReplacements,
$this->getPurifier()->purify($output) $this->getPurifier()->purify($output)
); );
$isHtml = true; $isHtml = true;
@ -167,8 +191,11 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
$config = HTMLPurifier_Config::createDefault(); $config = HTMLPurifier_Config::createDefault();
$config->set('Core.EscapeNonASCIICharacters', true); $config->set('Core.EscapeNonASCIICharacters', true);
$config->set('HTML.Allowed', 'p,br,b,a[href|target],i,table,tr,th[colspan],td[colspan],div,*[class]');
$config->set('Attr.AllowedFrameTargets', array('_blank')); $config->set('Attr.AllowedFrameTargets', array('_blank'));
$config->set(
'HTML.Allowed',
'p,br,b,a[href|target],i,ul,ol,li,table,tr,th[colspan],td[colspan],div,*[class]'
);
// This avoids permission problems: // This avoids permission problems:
// $config->set('Core.DefinitionCache', null); // $config->set('Core.DefinitionCache', null);
$config->set('Cache.DefinitionImpl', null); $config->set('Cache.DefinitionImpl', null);