mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-12 09:04:31 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4317c387fb | ||
|
c05639e0c9 | ||
|
b4136da73c | ||
|
0176ef4bb6 | ||
|
78a9b4d0da | ||
|
9ec687c904 |
@@ -10,23 +10,21 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->mask = '_- ';
|
// Lowercase letters
|
||||||
for ($c = 'a'; $c <= 'z'; $c++) {
|
$l = range('a', 'z');
|
||||||
$this->mask .= $c;
|
// Uppercase letters
|
||||||
}
|
$u = range('A', 'Z');
|
||||||
for ($c = 'A'; $c <= 'Z'; $c++) {
|
// Digits
|
||||||
$this->mask .= $c;
|
$d = range('0', '9');
|
||||||
}
|
// Special bytes used by UTF-8
|
||||||
for ($c = '0'; $c <= '9'; $c++) {
|
$b = array_map('chr', range(0x80, 0xFF));
|
||||||
$this->mask .= $c;
|
// All valid characters for the mask
|
||||||
} // cast-y, but should be fine
|
$c = array_merge($l, $u, $d, $b);
|
||||||
// special bytes used by UTF-8
|
// Concatenate all valid characters into a string
|
||||||
for ($i = 0x80; $i <= 0xFF; $i++) {
|
// Use '_- ' as an initial value
|
||||||
// We don't bother excluding invalid bytes in this range,
|
$this->mask = array_reduce($c, function ($carry, $value) {
|
||||||
// because the our restriction of well-formed UTF-8 will
|
return $carry . $value;
|
||||||
// prevent these from ever occurring.
|
}, '_- ');
|
||||||
$this->mask .= chr($i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
PHP's internal strcspn implementation is
|
PHP's internal strcspn implementation is
|
||||||
|
@@ -33,7 +33,11 @@ class HTMLPurifier_AttrTransform_TargetBlank extends HTMLPurifier_AttrTransform
|
|||||||
|
|
||||||
// XXX Kind of inefficient
|
// XXX Kind of inefficient
|
||||||
$url = $this->parser->parse($attr['href']);
|
$url = $this->parser->parse($attr['href']);
|
||||||
$scheme = $url->getSchemeObj($config, $context);
|
|
||||||
|
// Ignore invalid schemes (e.g. `javascript:`)
|
||||||
|
if (!($scheme = $url->getSchemeObj($config, $context))) {
|
||||||
|
return $attr;
|
||||||
|
}
|
||||||
|
|
||||||
if ($scheme->browsable && !$url->isBenign($config, $context)) {
|
if ($scheme->browsable && !$url->isBenign($config, $context)) {
|
||||||
$attr['target'] = '_blank';
|
$attr['target'] = '_blank';
|
||||||
|
@@ -287,13 +287,14 @@ class HTMLPurifier_DefinitionCache_Serializer extends HTMLPurifier_DefinitionCac
|
|||||||
} elseif (filegroup($dir) === posix_getgid()) {
|
} elseif (filegroup($dir) === posix_getgid()) {
|
||||||
$chmod = $chmod | 0070;
|
$chmod = $chmod | 0070;
|
||||||
} else {
|
} else {
|
||||||
// PHP's probably running as nobody, so we'll
|
// PHP's probably running as nobody, it is
|
||||||
// need to give global permissions
|
// not obvious how to fix this (777 is probably
|
||||||
$chmod = $chmod | 0777;
|
// bad if you are multi-user), let the user figure it out
|
||||||
|
$chmod = null;
|
||||||
}
|
}
|
||||||
trigger_error(
|
trigger_error(
|
||||||
'Directory ' . $dir . ' not writable, ' .
|
'Directory ' . $dir . ' not writable. ' .
|
||||||
'please chmod to ' . decoct($chmod),
|
($chmod === null ? '' : 'Please chmod to ' . decoct($chmod)),
|
||||||
E_USER_WARNING
|
E_USER_WARNING
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -71,7 +71,7 @@ class HTMLPurifier_DefinitionCacheFactory
|
|||||||
return $this->caches[$method][$type];
|
return $this->caches[$method][$type];
|
||||||
}
|
}
|
||||||
if (isset($this->implementations[$method]) &&
|
if (isset($this->implementations[$method]) &&
|
||||||
class_exists($class = $this->implementations[$method], false)) {
|
class_exists($class = $this->implementations[$method])) {
|
||||||
$cache = new $class($type);
|
$cache = new $class($type);
|
||||||
} else {
|
} else {
|
||||||
if ($method != 'Serializer') {
|
if ($method != 'Serializer') {
|
||||||
|
@@ -146,6 +146,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
|
|||||||
foreach ($this->_tidy->css as $k => $decls) {
|
foreach ($this->_tidy->css as $k => $decls) {
|
||||||
// $decls are all CSS declarations inside an @ selector
|
// $decls are all CSS declarations inside an @ selector
|
||||||
$new_decls = array();
|
$new_decls = array();
|
||||||
|
if (is_array($decls)) {
|
||||||
foreach ($decls as $selector => $style) {
|
foreach ($decls as $selector => $style) {
|
||||||
$selector = trim($selector);
|
$selector = trim($selector);
|
||||||
if ($selector === '') {
|
if ($selector === '') {
|
||||||
@@ -316,6 +317,9 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
|
|||||||
}
|
}
|
||||||
$new_decls[$selector] = $style;
|
$new_decls[$selector] = $style;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$new_css[$k] = $new_decls;
|
$new_css[$k] = $new_decls;
|
||||||
}
|
}
|
||||||
// remove stuff that shouldn't be used, could be reenabled
|
// remove stuff that shouldn't be used, could be reenabled
|
||||||
|
@@ -109,7 +109,7 @@ class HTMLPurifier_LanguageFactory
|
|||||||
} else {
|
} else {
|
||||||
$class = 'HTMLPurifier_Language_' . $pcode;
|
$class = 'HTMLPurifier_Language_' . $pcode;
|
||||||
$file = $this->dir . '/Language/classes/' . $code . '.php';
|
$file = $this->dir . '/Language/classes/' . $code . '.php';
|
||||||
if (file_exists($file) || class_exists($class, false)) {
|
if (file_exists($file) || class_exists($class)) {
|
||||||
$lang = new $class($config, $context);
|
$lang = new $class($config, $context);
|
||||||
} else {
|
} else {
|
||||||
// Go fallback
|
// Go fallback
|
||||||
|
@@ -101,7 +101,7 @@ class HTMLPurifier_Lexer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists('DOMDocument', false) &&
|
if (class_exists('DOMDocument') &&
|
||||||
method_exists('DOMDocument', 'loadHTML') &&
|
method_exists('DOMDocument', 'loadHTML') &&
|
||||||
!extension_loaded('domxml')
|
!extension_loaded('domxml')
|
||||||
) {
|
) {
|
||||||
|
@@ -214,6 +214,19 @@ text-align:right
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_keepImportantComments()
|
||||||
|
{
|
||||||
|
$this->assertCleanCSS(
|
||||||
|
"/*! Important */
|
||||||
|
div {
|
||||||
|
text-align:right /*! Important2 */
|
||||||
|
}",
|
||||||
|
"div {
|
||||||
|
text-align:right
|
||||||
|
}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_atSelector()
|
public function test_atSelector()
|
||||||
{
|
{
|
||||||
$this->assertCleanCSS(
|
$this->assertCleanCSS(
|
||||||
|
Reference in New Issue
Block a user