|
Revision 21, 1.0 kB
(checked in by admin, 18 years ago)
|
|
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Validates an integer representation of pixels according to the HTML spec. |
|---|
| 5 | */ |
|---|
| 6 | class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef |
|---|
| 7 | { |
|---|
| 8 | |
|---|
| 9 | public function validate($string, $config, $context) { |
|---|
| 10 | |
|---|
| 11 | $string = trim($string); |
|---|
| 12 | if ($string === '0') return $string; |
|---|
| 13 | if ($string === '') return false; |
|---|
| 14 | $length = strlen($string); |
|---|
| 15 | if (substr($string, $length - 2) == 'px') { |
|---|
| 16 | $string = substr($string, 0, $length - 2); |
|---|
| 17 | } |
|---|
| 18 | if (!is_numeric($string)) return false; |
|---|
| 19 | $int = (int) $string; |
|---|
| 20 | |
|---|
| 21 | if ($int < 0) return '0'; |
|---|
| 22 | |
|---|
| 23 | // upper-bound value, extremely high values can |
|---|
| 24 | // crash operating systems, see <http://ha.ckers.org/imagecrash.html> |
|---|
| 25 | // WARNING, above link WILL crash you if you're using Windows |
|---|
| 26 | |
|---|
| 27 | if ($int > 1200) return '1200'; |
|---|
| 28 | |
|---|
| 29 | return (string) $int; |
|---|
| 30 | |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | } |
|---|
| 34 | |
|---|