Changeset 1256
- Timestamp:
- 07/02/08 00:47:42
(2 months ago)
- Author:
- rats
- Message:
Updated HTMLpurifier to version 3.1.1
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r1255 |
r1256 |
|
| 2 | 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 | 3 | |
|---|
| | 4 | 2008-07-02 Benedikt Heintel |
|---|
| | 5 | - TOOLS: |
|---|
| | 6 | * Updated HTMLpurifier to version 3.1.1 |
|---|
| | 7 | |
|---|
| 4 | 8 | 2008-07-01 Marc Pujol |
|---|
| 5 | 9 | - GUI: |
|---|
| … | … | |
| 9 | 13 | - GUI: |
|---|
| 10 | 14 | * Fixed #1352 PHPmyadmin login from control panel not working (thanks Machaven) |
|---|
| | 15 | |
|---|
| | 16 | 2008-06-30 Benedikt Heintel |
|---|
| | 17 | - GUI: |
|---|
| | 18 | * Fixed #1367: Fatal Error after Login |
|---|
| 11 | 19 | |
|---|
| 12 | 20 | 2008-06-29 Benedikt Heintel |
|---|
| r1241 |
r1256 |
|
| 8 | 8 | * FILE, changes will be overwritten the next time the script is run. |
|---|
| 9 | 9 | * |
|---|
| 10 | | * @version 3.1.0 |
|---|
| | 10 | * @version 3.1.1 |
|---|
| 11 | 11 | * |
|---|
| 12 | 12 | * @warning |
|---|
| … | … | |
| 30 | 30 | require 'HTMLPurifier/ChildDef.php'; |
|---|
| 31 | 31 | require 'HTMLPurifier/Config.php'; |
|---|
| 32 | | require 'HTMLPurifier/ConfigDef.php'; |
|---|
| 33 | 32 | require 'HTMLPurifier/ConfigSchema.php'; |
|---|
| 34 | 33 | require 'HTMLPurifier/ContentSets.php'; |
|---|
| … | … | |
| 53 | 52 | require 'HTMLPurifier/Language.php'; |
|---|
| 54 | 53 | require 'HTMLPurifier/LanguageFactory.php'; |
|---|
| | 54 | require 'HTMLPurifier/Length.php'; |
|---|
| 55 | 55 | require 'HTMLPurifier/Lexer.php'; |
|---|
| 56 | 56 | require 'HTMLPurifier/PercentEncoder.php'; |
|---|
| … | … | |
| 67 | 67 | require 'HTMLPurifier/URIScheme.php'; |
|---|
| 68 | 68 | require 'HTMLPurifier/URISchemeRegistry.php'; |
|---|
| | 69 | require 'HTMLPurifier/UnitConverter.php'; |
|---|
| 69 | 70 | require 'HTMLPurifier/VarParser.php'; |
|---|
| 70 | 71 | require 'HTMLPurifier/VarParserException.php'; |
|---|
| … | … | |
| 73 | 74 | require 'HTMLPurifier/AttrDef/Integer.php'; |
|---|
| 74 | 75 | require 'HTMLPurifier/AttrDef/Lang.php'; |
|---|
| | 76 | require 'HTMLPurifier/AttrDef/Switch.php'; |
|---|
| 75 | 77 | require 'HTMLPurifier/AttrDef/Text.php'; |
|---|
| 76 | 78 | require 'HTMLPurifier/AttrDef/URI.php'; |
|---|
| … | … | |
| 117 | 119 | require 'HTMLPurifier/AttrTransform/Length.php'; |
|---|
| 118 | 120 | require 'HTMLPurifier/AttrTransform/Name.php'; |
|---|
| | 121 | require 'HTMLPurifier/AttrTransform/SafeEmbed.php'; |
|---|
| | 122 | require 'HTMLPurifier/AttrTransform/SafeObject.php'; |
|---|
| | 123 | require 'HTMLPurifier/AttrTransform/SafeParam.php'; |
|---|
| 119 | 124 | require 'HTMLPurifier/AttrTransform/ScriptRequired.php'; |
|---|
| 120 | 125 | require 'HTMLPurifier/ChildDef/Chameleon.php'; |
|---|
| … | … | |
| 125 | 130 | require 'HTMLPurifier/ChildDef/StrictBlockquote.php'; |
|---|
| 126 | 131 | require 'HTMLPurifier/ChildDef/Table.php'; |
|---|
| 127 | | require 'HTMLPurifier/ConfigDef/Directive.php'; |
|---|
| 128 | | require 'HTMLPurifier/ConfigDef/DirectiveAlias.php'; |
|---|
| 129 | | require 'HTMLPurifier/ConfigDef/Namespace.php'; |
|---|
| 130 | 132 | require 'HTMLPurifier/DefinitionCache/Decorator.php'; |
|---|
| 131 | 133 | require 'HTMLPurifier/DefinitionCache/Null.php'; |
|---|
| … | … | |
| 145 | 147 | require 'HTMLPurifier/HTMLModule/Proprietary.php'; |
|---|
| 146 | 148 | require 'HTMLPurifier/HTMLModule/Ruby.php'; |
|---|
| | 149 | require 'HTMLPurifier/HTMLModule/SafeEmbed.php'; |
|---|
| | 150 | require 'HTMLPurifier/HTMLModule/SafeObject.php'; |
|---|
| 147 | 151 | require 'HTMLPurifier/HTMLModule/Scripting.php'; |
|---|
| 148 | 152 | require 'HTMLPurifier/HTMLModule/StyleAttribute.php'; |
|---|
| … | … | |
| 160 | 164 | require 'HTMLPurifier/Injector/Linkify.php'; |
|---|
| 161 | 165 | require 'HTMLPurifier/Injector/PurifierLinkify.php'; |
|---|
| | 166 | require 'HTMLPurifier/Injector/SafeObject.php'; |
|---|
| 162 | 167 | require 'HTMLPurifier/Lexer/DOMLex.php'; |
|---|
| 163 | 168 | require 'HTMLPurifier/Lexer/DirectLex.php'; |
|---|
| … | … | |
| 180 | 185 | require 'HTMLPurifier/URIFilter/HostBlacklist.php'; |
|---|
| 181 | 186 | require 'HTMLPurifier/URIFilter/MakeAbsolute.php'; |
|---|
| | 187 | require 'HTMLPurifier/URIFilter/Munge.php'; |
|---|
| 182 | 188 | require 'HTMLPurifier/URIScheme/ftp.php'; |
|---|
| 183 | 189 | require 'HTMLPurifier/URIScheme/http.php'; |
|---|
| r1241 |
r1256 |
|
| 20 | 20 | |
|---|
| 21 | 21 | /* |
|---|
| 22 | | HTML Purifier 3.1.0 - Standards Compliant HTML Filtering |
|---|
| | 22 | HTML Purifier 3.1.1 - Standards Compliant HTML Filtering |
|---|
| 23 | 23 | Copyright (C) 2006-2008 Edward Z. Yang |
|---|
| 24 | 24 | |
|---|
| … | … | |
| 56 | 56 | |
|---|
| 57 | 57 | /** Version of HTML Purifier */ |
|---|
| 58 | | public $version = '3.1.0'; |
|---|
| | 58 | public $version = '3.1.1'; |
|---|
| 59 | 59 | |
|---|
| 60 | 60 | /** Constant with version of HTML Purifier */ |
|---|
| 61 | | const VERSION = '3.1.0'; |
|---|
| | 61 | const VERSION = '3.1.1'; |
|---|
| 62 | 62 | |
|---|
| 63 | 63 | /** Global configuration object */ |
|---|
| r1241 |
r1256 |
|
| 24 | 24 | require_once $__dir . '/HTMLPurifier/ChildDef.php'; |
|---|
| 25 | 25 | require_once $__dir . '/HTMLPurifier/Config.php'; |
|---|
| 26 | | require_once $__dir . '/HTMLPurifier/ConfigDef.php'; |
|---|
| 27 | 26 | require_once $__dir . '/HTMLPurifier/ConfigSchema.php'; |
|---|
| 28 | 27 | require_once $__dir . '/HTMLPurifier/ContentSets.php'; |
|---|
| … | … | |
| 47 | 46 | require_once $__dir . '/HTMLPurifier/Language.php'; |
|---|
| 48 | 47 | require_once $__dir . '/HTMLPurifier/LanguageFactory.php'; |
|---|
| | 48 | require_once $__dir . '/HTMLPurifier/Length.php'; |
|---|
| 49 | 49 | require_once $__dir . '/HTMLPurifier/Lexer.php'; |
|---|
| 50 | 50 | require_once $__dir . '/HTMLPurifier/PercentEncoder.php'; |
|---|
| … | … | |
| 61 | 61 | require_once $__dir . '/HTMLPurifier/URIScheme.php'; |
|---|
| 62 | 62 | require_once $__dir . '/HTMLPurifier/URISchemeRegistry.php'; |
|---|
| | 63 | require_once $__dir . '/HTMLPurifier/UnitConverter.php'; |
|---|
| 63 | 64 | require_once $__dir . '/HTMLPurifier/VarParser.php'; |
|---|
| 64 | 65 | require_once $__dir . '/HTMLPurifier/VarParserException.php'; |
|---|
| … | … | |
| 67 | 68 | require_once $__dir . '/HTMLPurifier/AttrDef/Integer.php'; |
|---|
| 68 | 69 | require_once $__dir . '/HTMLPurifier/AttrDef/Lang.php'; |
|---|
| | 70 | require_once $__dir . '/HTMLPurifier/AttrDef/Switch.php'; |
|---|
| 69 | 71 | require_once $__dir . '/HTMLPurifier/AttrDef/Text.php'; |
|---|
| 70 | 72 | require_once $__dir . '/HTMLPurifier/AttrDef/URI.php'; |
|---|
| … | … | |
| 111 | 113 | require_once $__dir . '/HTMLPurifier/AttrTransform/Length.php'; |
|---|
| 112 | 114 | require_once $__dir . '/HTMLPurifier/AttrTransform/Name.php'; |
|---|
| | 115 | require_once $__dir . '/HTMLPurifier/AttrTransform/SafeEmbed.php'; |
|---|
| | 116 | require_once $__dir . '/HTMLPurifier/AttrTransform/SafeObject.php'; |
|---|
| | 117 | require_once $__dir . '/HTMLPurifier/AttrTransform/SafeParam.php'; |
|---|
| 113 | 118 | require_once $__dir . '/HTMLPurifier/AttrTransform/ScriptRequired.php'; |
|---|
| 114 | 119 | require_once $__dir . '/HTMLPurifier/ChildDef/Chameleon.php'; |
|---|
| … | … | |
| 119 | 124 | require_once $__dir . '/HTMLPurifier/ChildDef/StrictBlockquote.php'; |
|---|
| 120 | 125 | require_once $__dir . '/HTMLPurifier/ChildDef/Table.php'; |
|---|
| 121 | | require_once $__dir . '/HTMLPurifier/ConfigDef/Directive.php'; |
|---|
| 122 | | require_once $__dir . '/HTMLPurifier/ConfigDef/DirectiveAlias.php'; |
|---|
| 123 | | require_once $__dir . '/HTMLPurifier/ConfigDef/Namespace.php'; |
|---|
| 124 | 126 | require_once $__dir . '/HTMLPurifier/DefinitionCache/Decorator.php'; |
|---|
| 125 | 127 | require_once $__dir . '/HTMLPurifier/DefinitionCache/Null.php'; |
|---|
| … | … | |
| 139 | 141 | require_once $__dir . '/HTMLPurifier/HTMLModule/Proprietary.php'; |
|---|
| 140 | 142 | require_once $__dir . '/HTMLPurifier/HTMLModule/Ruby.php'; |
|---|
| | 143 | require_once $__dir . '/HTMLPurifier/HTMLModule/SafeEmbed.php'; |
|---|
| | 144 | require_once $__dir . '/HTMLPurifier/HTMLModule/SafeObject.php'; |
|---|
| 141 | 145 | require_once $__dir . '/HTMLPurifier/HTMLModule/Scripting.php'; |
|---|
| 142 | 146 | require_once $__dir . '/HTMLPurifier/HTMLModule/StyleAttribute.php'; |
|---|
| … | … | |
| 154 | 158 | require_once $__dir . '/HTMLPurifier/Injector/Linkify.php'; |
|---|
| 155 | 159 | require_once $__dir . '/HTMLPurifier/Injector/PurifierLinkify.php'; |
|---|
| | 160 | require_once $__dir . '/HTMLPurifier/Injector/SafeObject.php'; |
|---|
| 156 | 161 | require_once $__dir . '/HTMLPurifier/Lexer/DOMLex.php'; |
|---|
| 157 | 162 | require_once $__dir . '/HTMLPurifier/Lexer/DirectLex.php'; |
|---|
| … | … | |
| 174 | 179 | require_once $__dir . '/HTMLPurifier/URIFilter/HostBlacklist.php'; |
|---|
| 175 | 180 | require_once $__dir . '/HTMLPurifier/URIFilter/MakeAbsolute.php'; |
|---|
| | 181 | require_once $__dir . '/HTMLPurifier/URIFilter/Munge.php'; |
|---|
| 176 | 182 | require_once $__dir . '/HTMLPurifier/URIScheme/ftp.php'; |
|---|
| 177 | 183 | require_once $__dir . '/HTMLPurifier/URIScheme/http.php'; |
|---|
| r1241 |
r1256 |
|
| 52 | 52 | * @warning This processing is inconsistent with XML's whitespace handling |
|---|
| 53 | 53 | * as specified by section 3.3.3 and referenced XHTML 1.0 section |
|---|
| 54 | | * 4.7. Compliant processing requires all line breaks normalized |
|---|
| 55 | | * to "\n", so the fix is not as simple as fixing it in this |
|---|
| 56 | | * function. Trim and whitespace collapsing are supposed to only |
|---|
| 57 | | * occur in NMTOKENs. However, note that we are NOT necessarily |
|---|
| 58 | | * parsing XML, thus, this behavior may still be correct. |
|---|
| | 54 | * 4.7. However, note that we are NOT necessarily |
|---|
| | 55 | * parsing XML, thus, this behavior may still be correct. We |
|---|
| | 56 | * assume that newlines have been normalized. |
|---|
| 59 | 57 | */ |
|---|
| 60 | 58 | public function parseCDATA($string) { |
|---|
| 61 | 59 | $string = trim($string); |
|---|
| 62 | | $string = str_replace("\n", '', $string); |
|---|
| 63 | | $string = str_replace(array("\r", "\t"), ' ', $string); |
|---|
| | 60 | $string = str_replace(array("\n", "\t", "\r"), ' ', $string); |
|---|
| 64 | 61 | return $string; |
|---|
| 65 | 62 | } |
|---|
| r1241 |
r1256 |
|
| 29 | 29 | $declarations = explode(';', $css); |
|---|
| 30 | 30 | $propvalues = array(); |
|---|
| | 31 | |
|---|
| | 32 | /** |
|---|
| | 33 | * Name of the current CSS property being validated. |
|---|
| | 34 | */ |
|---|
| | 35 | $property = false; |
|---|
| | 36 | $context->register('CurrentCSSProperty', $property); |
|---|
| 31 | 37 | |
|---|
| 32 | 38 | foreach ($declarations as $declaration) { |
|---|
| … | … | |
| 62 | 68 | } |
|---|
| 63 | 69 | |
|---|
| | 70 | $context->destroy('CurrentCSSProperty'); |
|---|
| | 71 | |
|---|
| 64 | 72 | // procedure does not write the new CSS simultaneously, so it's |
|---|
| 65 | 73 | // slightly inefficient, but it's the only way of getting rid of |
|---|
| r1241 |
r1256 |
|
| 17 | 17 | ); |
|---|
| 18 | 18 | |
|---|
| 19 | | $string = $this->parseCDATA($string); |
|---|
| 20 | 19 | // assume that no font names contain commas in them |
|---|
| 21 | 20 | $fonts = explode(',', $string); |
|---|
| … | … | |
| 36 | 35 | if ($font[$length - 1] !== $quote) continue; |
|---|
| 37 | 36 | $font = substr($font, 1, $length - 2); |
|---|
| 38 | | // double-backslash processing is buggy |
|---|
| 39 | | $font = str_replace("\\$quote", $quote, $font); // de-escape quote |
|---|
| 40 | | $font = str_replace("\\\n", "\n", $font); // de-escape newlines |
|---|
| | 37 | |
|---|
| | 38 | $new_font = ''; |
|---|
| | 39 | for ($i = 0, $c = strlen($font); $i < $c; $i++) { |
|---|
| | 40 | if ($font[$i] === '\\') { |
|---|
| | 41 | $i++; |
|---|
| | 42 | if ($i >= $c) { |
|---|
| | 43 | $new_font .= '\\'; |
|---|
| | 44 | break; |
|---|
| | 45 | } |
|---|
| | 46 | if (ctype_xdigit($font[$i])) { |
|---|
| | 47 | $code = $font[$i]; |
|---|
| | 48 | for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) { |
|---|
| | 49 | if (!ctype_xdigit($font[$i])) break; |
|---|
| | 50 | $code .= $font[$i]; |
|---|
| | 51 | } |
|---|
| | 52 | // We have to be extremely careful when adding |
|---|
| | 53 | // new characters, to make sure we're not breaking |
|---|
| | 54 | // the encoding. |
|---|
| | 55 | $char = HTMLPurifier_Encoder::unichr(hexdec($code)); |
|---|
| | 56 | if (HTMLPurifier_Encoder::cleanUTF8($char) === '') continue; |
|---|
| | 57 | $new_font .= $char; |
|---|
| | 58 | if ($i < $c && trim($font[$i]) !== '') $i--; |
|---|
| | 59 | continue; |
|---|
| | 60 | } |
|---|
| | 61 | if ($font[$i] === "\n") continue; |
|---|
| | 62 | } |
|---|
| | 63 | $new_font .= $font[$i]; |
|---|
| | 64 | } |
|---|
| | 65 | |
|---|
| | 66 | $font = $new_font; |
|---|
| 41 | 67 | } |
|---|
| 42 | 68 | // $font is a pure representation of the font name |
|---|
| 43 | 69 | |
|---|
| 44 | | if (ctype_alnum($font)) { |
|---|
| | 70 | if (ctype_alnum($font) && $font !== '') { |
|---|
| 45 | 71 | // very simple font, allow it in unharmed |
|---|
| 46 | 72 | $final .= $font . ', '; |
|---|
| … | … | |
| 51 | 77 | |
|---|
| 52 | 78 | // armor single quotes and new lines |
|---|
| | 79 | $font = str_replace("\\", "\\\\", $font); |
|---|
| 53 | 80 | $font = str_replace("'", "\\'", $font); |
|---|
| 54 | | $font = str_replace("\n", "\\\n", $font); |
|---|
| 55 | 81 | $final .= "'$font', "; |
|---|
| 56 | 82 | } |
|---|
| r1241 |
r1256 |
|
| 7 | 7 | { |
|---|
| 8 | 8 | |
|---|
| 9 | | /** |
|---|
| 10 | | * Valid unit lookup table. |
|---|
| 11 | | * @warning The code assumes all units are two characters long. Be careful |
|---|
| 12 | | * if we have to change this behavior! |
|---|
| 13 | | */ |
|---|
| 14 | | protected $units = array('em' => true, 'ex' => true, 'px' => true, 'in' => true, |
|---|
| 15 | | 'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true); |
|---|
| 16 | | /** |
|---|
| 17 | | * Instance of HTMLPurifier_AttrDef_Number to defer number validation to |
|---|
| 18 | | */ |
|---|
| 19 | | protected $number_def; |
|---|
| | 9 | protected $min, $max; |
|---|
| 20 | 10 | |
|---|
| 21 | 11 | /** |
|---|
| 22 | | * @param $non_negative Bool indication whether or not negative values are |
|---|
| 23 | | * allowed. |
|---|
| | 12 | * @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable. |
|---|
| | 13 | * @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable. |
|---|
| 24 | 14 | */ |
|---|
| 25 | | public function __construct($non_negative = false) { |
|---|
| 26 | | $this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative); |
|---|
| | 15 | public function __construct($min = null, $max = null) { |
|---|
| | 16 | $this->min = $min !== null ? HTMLPurifier_Length::make($min) : null; |
|---|
| | 17 | $this->max = $max !== null ? HTMLPurifier_Length::make($max) : null; |
|---|
| 27 | 18 | } |
|---|
| 28 | 19 | |
|---|
| 29 | | public function validate($length, $config, $context) { |
|---|
| | 20 | public function validate($string, $config, $context) { |
|---|
| | 21 | $string = $this->parseCDATA($string); |
|---|
| 30 | 22 | |
|---|
| 31 | | $length = $this->parseCDATA($length); |
|---|
| 32 | | if ($length === '') return false; |
|---|
| 33 | | if ($length === '0') return '0'; |
|---|
| 34 | | $strlen = strlen($length); |
|---|
| 35 | | if ($strlen === 1) return false; // impossible! |
|---|
| | 23 | // Optimizations |
|---|
| | 24 | if ($string === '') return false; |
|---|
| | 25 | if ($string === '0') return '0'; |
|---|
| | 26 | if (strlen($string) === 1) return false; |
|---|
| 36 | 27 | |
|---|
| 37 | | // we assume all units are two characters |
|---|
| 38 | | $unit = substr($length, $strlen - 2); |
|---|
| 39 | | if (!ctype_lower($unit)) $unit = strtolower($unit); |
|---|
| 40 | | $number = substr($length, 0, $strlen - 2); |
|---|
| | 28 | $length = HTMLPurifier_Length::make($string); |
|---|
| | 29 | if (!$length->isValid()) return false; |
|---|
| 41 | 30 | |
|---|
| 42 | | if (!isset($this->units[$unit])) return false; |
|---|
| | 31 | if ($this->min) { |
|---|
| | 32 | $c = $length->compareTo($this->min); |
|---|
| | 33 | if ($c === false) return false; |
|---|
| | 34 | if ($c < 0) return false; |
|---|
| | 35 | } |
|---|
| | 36 | if ($this->max) { |
|---|
| | 37 | $c = $length->compareTo($this->max); |
|---|
| | 38 | if ($c === false) return false; |
|---|
| | 39 | if ($c > 0) return false; |
|---|
| | 40 | } |
|---|
| 43 | 41 | |
|---|
| 44 | | $number = $this->number_def->validate($number, $config, $context); |
|---|
| 45 | | if ($number === false) return false; |
|---|
| 46 | | |
|---|
| 47 | | return $number . $unit; |
|---|
| 48 | | |
|---|
| | 42 | return $length->toString(); |
|---|
| 49 | 43 | } |
|---|
| 50 | 44 | |
|---|
| r1241 |
r1256 |
|
| 19 | 19 | } |
|---|
| 20 | 20 | |
|---|
| | 21 | /** |
|---|
| | 22 | * @warning Some contexts do not pass $config, $context. These |
|---|
| | 23 | * variables should not be used without checking HTMLPurifier_Length |
|---|
| | 24 | */ |
|---|
| 21 | 25 | public function validate($number, $config, $context) { |
|---|
| 22 | 26 | |
|---|
| r1241 |
r1256 |
|
| 14 | 14 | 'line-through' => true, |
|---|
| 15 | 15 | 'overline' => true, |
|---|
| 16 | | 'underline' => true |
|---|
| | 16 | 'underline' => true, |
|---|
| 17 | 17 | ); |
|---|
| 18 | 18 | |
|---|
| 19 | 19 | $string = strtolower($this->parseCDATA($string)); |
|---|
| | 20 | |
|---|
| | 21 | if ($string === 'none') return $string; |
|---|
| | 22 | |
|---|
| 20 | 23 | $parts = explode(' ', $string); |
|---|
| 21 | 24 | $final = ''; |
|---|
| r1241 |
r1256 |
|
| 6 | 6 | class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef |
|---|
| 7 | 7 | { |
|---|
| | 8 | |
|---|
| | 9 | protected $max; |
|---|
| | 10 | |
|---|
| | 11 | public function __construct($max = null) { |
|---|
| | 12 | $this->max = $max; |
|---|
| | 13 | } |
|---|
| 8 | 14 | |
|---|
| 9 | 15 | public function validate($string, $config, $context) { |
|---|
| … | … | |
| 25 | 31 | // WARNING, above link WILL crash you if you're using Windows |
|---|
| 26 | 32 | |
|---|
| 27 | | if ($int > 1200) return '1200'; |
|---|
| | 33 | if ($this->max !== null && $int > $this->max) return (string) $this->max; |
|---|
| 28 | 34 | |
|---|
| 29 | 35 | return (string) $int; |
|---|
| … | … | |
| 31 | 37 | } |
|---|
| 32 | 38 | |
|---|
| | 39 | public function make($string) { |
|---|
| | 40 | if ($string === '') $max = null; |
|---|
| | 41 | else $max = (int) $string; |
|---|
| | 42 | $class = get_class($this); |
|---|
| | 43 | return new $class($max); |
|---|
| | 44 | } |
|---|
| | 45 | |
|---|
| 33 | 46 | } |
|---|
| 34 | 47 | |
|---|
| r1241 |
r1256 |
|
| 17 | 17 | $this->parser = new HTMLPurifier_URIParser(); |
|---|
| 18 | 18 | $this->embedsResource = (bool) $embeds_resource; |
|---|
| | 19 | } |
|---|
| | 20 | |
|---|
| | 21 | public function make($string) { |
|---|
| | 22 | $embeds = (bool) $string; |
|---|
| | 23 | return new HTMLPurifier_AttrDef_URI($embeds); |
|---|
| 19 | 24 | } |
|---|
| 20 | 25 | |
|---|
| … | … | |
| 51 | 56 | if (!$result) break; |
|---|
| 52 | 57 | |
|---|
| | 58 | // Post chained filtering |
|---|
| | 59 | $result = $uri_def->postFilter($uri, $config, $context); |
|---|
| | 60 | if (!$result) break; |
|---|
| | 61 | |
|---|
| 53 | 62 | // survived gauntlet |
|---|
| 54 | 63 | $ok = true; |
|---|
| … | … | |
| 60 | 69 | |
|---|
| 61 | 70 | // back to string |
|---|
| 62 | | $result = $uri->toString(); |
|---|
| 63 | | |
|---|
| 64 | | // munge entire URI if necessary |
|---|
| 65 | | if ( |
|---|
| 66 | | !is_null($uri->host) && // indicator for authority |
|---|
| 67 | | !empty($scheme_obj->browsable) && |
|---|
| 68 | | !is_null($munge = $config->get('URI', 'Munge')) |
|---|
| 69 | | ) { |
|---|
| 70 | | $result = str_replace('%s', rawurlencode($result), $munge); |
|---|
| 71 | | } |
|---|
| 72 | | |
|---|
| 73 | | return $result; |
|---|
| | 71 | return $uri->toString(); |
|---|
| 74 | 72 | |
|---|
| 75 | 73 | } |
|---|
| r1241 |
r1256 |
|
| 44 | 44 | $d_defs = $definition->info_global_attr; |
|---|
| 45 | 45 | |
|---|
| 46 | | // reference attributes for easy manipulation |
|---|
| 47 | | $attr =& $token->attr; |
|---|
| | 46 | // don't update token until the very end, to ensure an atomic update |
|---|
| | 47 | $attr = $token->attr; |
|---|
| 48 | 48 | |
|---|
| 49 | 49 | // do global transformations (pre) |
|---|
| … | … | |
| 140 | 140 | } |
|---|
| 141 | 141 | |
|---|
| | 142 | $token->attr = $attr; |
|---|
| | 143 | |
|---|
| 142 | 144 | // destroy CurrentToken if we made it ourselves |
|---|
| 143 | 145 | if (!$current_token) $context->destroy('CurrentToken'); |
|---|
| r1241 |
r1256 |
|
| 91 | 91 | $this->info['border-right-width'] = new HTMLPurifier_AttrDef_CSS_Composite(array( |
|---|
| 92 | 92 | new HTMLPurifier_AttrDef_Enum(array('thin', 'medium', 'thick')), |
|---|
| 93 | | new HTMLPurifier_AttrDef_CSS_Length(true) //disallow negative |
|---|
| | 93 | new HTMLPurifier_AttrDef_CSS_Length('0') //disallow negative |
|---|
| 94 | 94 | )); |
|---|
| 95 | 95 | |
|---|
| … | … | |
| 117 | 117 | new HTMLPurifier_AttrDef_Enum(array('normal')), |
|---|
| 118 | 118 | new HTMLPurifier_AttrDef_CSS_Number(true), // no negatives |
|---|
| 119 | | new HTMLPurifier_AttrDef_CSS_Length(true), |
|---|
| | 119 | new HTMLPurifier_AttrDef_CSS_Length('0'), |
|---|
| 120 | 120 | new HTMLPurifier_AttrDef_CSS_Percentage(true) |
|---|
| 121 | 121 | )); |
|---|
| … | … | |
| 139 | 139 | $this->info['padding-left'] = |
|---|
| 140 | 140 | $this->info['padding-right'] = new HTMLPurifier_AttrDef_CSS_Composite(array( |
|---|
| 141 | | new HTMLPurifier_AttrDef_CSS_Length(true), |
|---|
| | 141 | new HTMLPurifier_AttrDef_CSS_Length('0'), |
|---|
| 142 | 142 | new HTMLPurifier_AttrDef_CSS_Percentage(true) |
|---|
| 143 | 143 | )); |
|---|
| … | … | |
| 150 | 150 | )); |
|---|
| 151 | 151 | |
|---|
| | 152 | $trusted_wh = new HTMLPurifier_AttrDef_CSS_Composite(array( |
|---|
| | 153 | new HTMLPurifier_AttrDef_CSS_Length('0'), |
|---|
| | 154 | new HTMLPurifier_AttrDef_CSS_Percentage(true), |
|---|
| | 155 | new HTMLPurifier_AttrDef_Enum(array('auto')) |
|---|
| | 156 | )); |
|---|
| | 157 | $max = $config->get('CSS', 'MaxImgLength'); |
|---|
| | 158 | |
|---|
| 152 | 159 | $this->info['width'] = |
|---|
| 153 | 160 | $this->info['height'] = |
|---|
| 154 | | new HTMLPurifier_AttrDef_CSS_DenyElementDecorator( |
|---|
| 155 | | new HTMLPurifier_AttrDef_CSS_Composite(array( |
|---|
| 156 | | new HTMLPurifier_AttrDef_CSS_Length(true), |
|---|
| 157 | | new HTMLPurifier_AttrDef_CSS_Percentage(true), |
|---|
| 158 | | new HTMLPurifier_AttrDef_Enum(array('auto')) |
|---|
| 159 | | )), 'img'); |
|---|
| | 161 | $max === null ? |
|---|
| | 162 | $trusted_wh : |
|---|
| | 163 | new HTMLPurifier_AttrDef_Switch('img', |
|---|
| | 164 | // For img tags: |
|---|
| | 165 | new HTMLPurifier_AttrDef_CSS_Composite(array( |
|---|
| | 166 | new HTMLPurifier_AttrDef_CSS_Length('0', $max), |
|---|
| | 167 | new HTMLPurifier_AttrDef_Enum(array('auto')) |
|---|
| | 168 | )), |
|---|
| | 169 | // For everyone else: |
|---|
| | 170 | $trusted_wh |
|---|
| | 171 | ); |
|---|
| 160 | 172 | |
|---|
| 161 | 173 | $this->info['text-decoration'] = new HTMLPurifier_AttrDef_CSS_TextDecoration(); |
|---|
| r1241 |
r1256 |
|
| 56 | 56 | |
|---|
| 57 | 57 | // generator |
|---|
| 58 | | static $gen = null; |
|---|
| 59 | | if ($gen === null) { |
|---|
| 60 | | $gen = new HTMLPurifier_Generator(); |
|---|
| 61 | | } |
|---|
| | 58 | $gen = new HTMLPurifier_Generator($config, $context); |
|---|
| 62 | 59 | |
|---|
| 63 | 60 | foreach ($tokens_of_children as $token) { |
|---|
| … | … | |
| 84 | 81 | } elseif ($pcdata_allowed && $escape_invalid_children) { |
|---|
| 85 | 82 | $result[] = new HTMLPurifier_Token_Text( |
|---|
| 86 | | $gen->generateFromToken($token, $config) |
|---|
| | 83 | $gen->generateFromToken($token) |
|---|
| 87 | 84 | ); |
|---|
| 88 | 85 | } |
|---|
| … | … | |
| 95 | 92 | $result[] = |
|---|
| 96 | 93 | new HTMLPurifier_Token_Text( |
|---|
| 97 | | $gen->generateFromToken( $token, $config ) |
|---|
| | 94 | $gen->generateFromToken($token) |
|---|
| 98 | 95 | ); |
|---|
| 99 | 96 | } else { |
|---|
| r1241 |
r1256 |
|
| 21 | 21 | * HTML Purifier's version |
|---|
| 22 | 22 | */ |
|---|
| 23 | | public $version = '3.1.0'; |
|---|
| | 23 | public $version = '3.1.1'; |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | /** |
|---|
| … | … | |
| 126 | 126 | return; |
|---|
| 127 | 127 | } |
|---|
| 128 | | if ($this->def->info[$namespace][$key]->class == 'alias') { |
|---|
| | 128 | if (isset($this->def->info[$namespace][$key]->isAlias)) { |
|---|
| 129 | 129 | $d = $this->def->info[$namespace][$key]; |
|---|
| 130 | 130 | trigger_error('Cannot get value from aliased directive, use real name ' . $d->namespace . '.' . $d->name, |
|---|
| … | … | |
| 197 | 197 | return; |
|---|
| 198 | 198 | } |
|---|
| 199 | | if ($this->def->info[$namespace][$key]->class == 'alias') { |
|---|
| | 199 | $def = $this->def->info[$namespace][$key]; |
|---|
| | 200 | |
|---|
| | 201 | if (isset($def->isAlias)) { |
|---|
| 200 | 202 | if ($from_alias) { |
|---|
| 201 | 203 | trigger_error('Double-aliases not allowed, please fix '. |
|---|
| … | … | |
| 203 | 205 | return; |
|---|
| 204 | 206 | } |
|---|
| 205 | | $this->set($new_ns = $this->def->info[$namespace][$key]->namespace, |
|---|
| 206 | | $new_dir = $this->def->info[$namespace][$key]->name, |
|---|
| | 207 | $this->set($new_ns = $def->namespace, |
|---|
| | 208 | $new_dir = $def->name, |
|---|
| 207 | 209 | $value, true); |
|---|
| 208 | 210 | trigger_error("$namespace.$key is an alias, preferred directive name is $new_ns.$new_dir", E_USER_NOTICE); |
|---|
| 209 | 211 | return; |
|---|
| 210 | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | // Raw type might be negative when using the fully optimized form |
|---|
| | 215 | // of stdclass, which indicates allow_null == true |
|---|
| | 216 | $rtype = is_int($def) ? $def : $def->type; |
|---|
| | 217 | if ($rtype < 0) { |
|---|
| | 218 | $type = -$rtype; |
|---|
| | 219 | $allow_null = true; |
|---|
| | 220 | } else { |
|---|
| | 221 | $type = $rtype; |
|---|
| | 222 | $allow_null = isset($def->allow_null); |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| 211 | 225 | try { |
|---|
| 212 | | $value = $this->parser->parse( |
|---|
| 213 | | $value, |
|---|
| 214 | | $type = $this->def->info[$namespace][$key]->type, |
|---|
| 215 | | $this->def->info[$namespace][$key]->allow_null |
|---|
| 216 | | ); |
|---|
| | 226 | $value = $this->parser->parse($value, $type, $allow_null); |
|---|
| 217 | 227 | } catch (HTMLPurifier_VarParserException $e) { |
|---|
| 218 | | trigger_error('Value for ' . "$namespace.$key" . ' is of invalid type, should be ' . $type, E_USER_WARNING); |
|---|
| 219 | | return; |
|---|
| 220 | | } |
|---|
| 221 | | if (is_string($value)) { |
|---|
| | 228 | trigger_error('Value for ' . "$namespace.$key" . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); |
|---|
| | 229 | return; |
|---|
| | 230 | } |
|---|
| | 231 | if (is_string($value) && is_object($def)) { |
|---|
| 222 | 232 | // resolve value alias if defined |
|---|
| 223 | | if (isset($this->def->info[$namespace][$key]->aliases[$value])) { |
|---|
| 224 | | $value = $this->def->info[$namespace][$key]->aliases[$value]; |
|---|
| 225 | | } |
|---|
| 226 | | if ($this->def->info[$namespace][$key]->allowed !== true) { |
|---|
| 227 | | // check to see if the value is allowed |
|---|
| 228 | | if (!isset($this->def->info[$namespace][$key]->allowed[$value])) { |
|---|
| 229 | | trigger_error('Value not supported, valid values are: ' . |
|---|
| 230 | | $this->_listify($this->def->info[$namespace][$key]->allowed), E_USER_WARNING); |
|---|
| 231 | | return; |
|---|
| 232 | | } |
|---|
| | 233 | if (isset($def->aliases[$value])) { |
|---|
| | 234 | $value = $def->aliases[$value]; |
|---|
| | 235 | } |
|---|
| | 236 | // check to see if the value is allowed |
|---|
| | 237 | if (isset($def->allowed) && !isset($def->allowed[$value])) { |
|---|
| | 238 | trigger_error('Value not supported, valid values are: ' . |
|---|
| | 239 | $this->_listify($def->allowed), E_USER_WARNING); |
|---|
| | 240 | return; |
|---|
| 233 | 241 | } |
|---|
| 234 | 242 | } |
|---|
| … | … | |
| 387 | 395 | if (!isset($allowed_directives["$ns.$directive"]) && !isset($allowed_ns[$ns])) continue; |
|---|
| 388 | 396 | } |
|---|
| 389 | | if ($def->class == 'alias') continue; |
|---|
| | 397 | if (isset($def->isAlias)) continue; |
|---|
| 390 | 398 | if ($directive == 'DefinitionID' || $directive == 'DefinitionRev') continue; |
|---|
| 391 | 399 | $ret[] = array($ns, $directive); |
|---|
| r1241 |
r1256 |
|
| 13 | 13 | |
|---|
| 14 | 14 | /** |
|---|
| 15 | | * Definition of the directives. |
|---|
| | 15 | * Definition of the directives. The structure of this is: |
|---|
| | 16 | * |
|---|
| | 17 | * array( |
|---|
| | 18 | * 'Namespace' => array( |
|---|
| | 19 | * 'Directive' => new stdclass(), |
|---|
| | 20 | * ) |
|---|
| | 21 | * ) |
|---|
| | 22 | * |
|---|
| | 23 | * The stdclass may have the following properties: |
|---|
| | 24 | * |
|---|
| | 25 | * - If isAlias isn't set: |
|---|
| | 26 | * - type: Integer type of directive, see HTMLPurifier_VarParser for definitions |
|---|
| | 27 | * - allow_null: If set, this directive allows null values |
|---|
| | 28 | * - aliases: If set, an associative array of value aliases to real values |
|---|
| | 29 | * - allowed: If set, a lookup array of allowed (string) values |
|---|
| | 30 | * - If isAlias is set: |
|---|
| | 31 | * - namespace: Namespace this directive aliases to |
|---|
| | 32 | |
|---|
|