aboutsummaryrefslogtreecommitdiffstats
path: root/library/HTMLPurifier/URIScheme
diff options
context:
space:
mode:
Diffstat (limited to 'library/HTMLPurifier/URIScheme')
-rw-r--r--library/HTMLPurifier/URIScheme/data.php127
-rw-r--r--library/HTMLPurifier/URIScheme/file.php44
-rw-r--r--library/HTMLPurifier/URIScheme/ftp.php58
-rw-r--r--library/HTMLPurifier/URIScheme/http.php36
-rw-r--r--library/HTMLPurifier/URIScheme/https.php18
-rw-r--r--library/HTMLPurifier/URIScheme/mailto.php40
-rw-r--r--library/HTMLPurifier/URIScheme/news.php35
-rw-r--r--library/HTMLPurifier/URIScheme/nntp.php32
8 files changed, 0 insertions, 390 deletions
diff --git a/library/HTMLPurifier/URIScheme/data.php b/library/HTMLPurifier/URIScheme/data.php
deleted file mode 100644
index 6ebca4984..000000000
--- a/library/HTMLPurifier/URIScheme/data.php
+++ /dev/null
@@ -1,127 +0,0 @@
-<?php
-
-/**
- * Implements data: URI for base64 encoded images supported by GD.
- */
-class HTMLPurifier_URIScheme_data extends HTMLPurifier_URIScheme
-{
- /**
- * @type bool
- */
- public $browsable = true;
-
- /**
- * @type array
- */
- public $allowed_types = array(
- // you better write validation code for other types if you
- // decide to allow them
- 'image/jpeg' => true,
- 'image/gif' => true,
- 'image/png' => true,
- );
- // this is actually irrelevant since we only write out the path
- // component
- /**
- * @type bool
- */
- public $may_omit_host = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $result = explode(',', $uri->path, 2);
- $is_base64 = false;
- $charset = null;
- $content_type = null;
- if (count($result) == 2) {
- list($metadata, $data) = $result;
- // do some legwork on the metadata
- $metas = explode(';', $metadata);
- while (!empty($metas)) {
- $cur = array_shift($metas);
- if ($cur == 'base64') {
- $is_base64 = true;
- break;
- }
- if (substr($cur, 0, 8) == 'charset=') {
- // doesn't match if there are arbitrary spaces, but
- // whatever dude
- if ($charset !== null) {
- continue;
- } // garbage
- $charset = substr($cur, 8); // not used
- } else {
- if ($content_type !== null) {
- continue;
- } // garbage
- $content_type = $cur;
- }
- }
- } else {
- $data = $result[0];
- }
- if ($content_type !== null && empty($this->allowed_types[$content_type])) {
- return false;
- }
- if ($charset !== null) {
- // error; we don't allow plaintext stuff
- $charset = null;
- }
- $data = rawurldecode($data);
- if ($is_base64) {
- $raw_data = base64_decode($data);
- } else {
- $raw_data = $data;
- }
- // XXX probably want to refactor this into a general mechanism
- // for filtering arbitrary content types
- $file = tempnam("/tmp", "");
- file_put_contents($file, $raw_data);
- if (function_exists('exif_imagetype')) {
- $image_code = exif_imagetype($file);
- unlink($file);
- } elseif (function_exists('getimagesize')) {
- set_error_handler(array($this, 'muteErrorHandler'));
- $info = getimagesize($file);
- restore_error_handler();
- unlink($file);
- if ($info == false) {
- return false;
- }
- $image_code = $info[2];
- } else {
- trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
- }
- $real_content_type = image_type_to_mime_type($image_code);
- if ($real_content_type != $content_type) {
- // we're nice guys; if the content type is something else we
- // support, change it over
- if (empty($this->allowed_types[$real_content_type])) {
- return false;
- }
- $content_type = $real_content_type;
- }
- // ok, it's kosher, rewrite what we need
- $uri->userinfo = null;
- $uri->host = null;
- $uri->port = null;
- $uri->fragment = null;
- $uri->query = null;
- $uri->path = "$content_type;base64," . base64_encode($raw_data);
- return true;
- }
-
- /**
- * @param int $errno
- * @param string $errstr
- */
- public function muteErrorHandler($errno, $errstr)
- {
- }
-}
diff --git a/library/HTMLPurifier/URIScheme/file.php b/library/HTMLPurifier/URIScheme/file.php
deleted file mode 100644
index 215be4ba8..000000000
--- a/library/HTMLPurifier/URIScheme/file.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-/**
- * Validates file as defined by RFC 1630 and RFC 1738.
- */
-class HTMLPurifier_URIScheme_file extends HTMLPurifier_URIScheme
-{
- /**
- * Generally file:// URLs are not accessible from most
- * machines, so placing them as an img src is incorrect.
- * @type bool
- */
- public $browsable = false;
-
- /**
- * Basically the *only* URI scheme for which this is true, since
- * accessing files on the local machine is very common. In fact,
- * browsers on some operating systems don't understand the
- * authority, though I hear it is used on Windows to refer to
- * network shares.
- * @type bool
- */
- public $may_omit_host = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- // Authentication method is not supported
- $uri->userinfo = null;
- // file:// makes no provisions for accessing the resource
- $uri->port = null;
- // While it seems to work on Firefox, the querystring has
- // no possible effect and is thus stripped.
- $uri->query = null;
- return true;
- }
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/ftp.php b/library/HTMLPurifier/URIScheme/ftp.php
deleted file mode 100644
index 1eb43ee5c..000000000
--- a/library/HTMLPurifier/URIScheme/ftp.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-/**
- * Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738.
- */
-class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme
-{
- /**
- * @type int
- */
- public $default_port = 21;
-
- /**
- * @type bool
- */
- public $browsable = true; // usually
-
- /**
- * @type bool
- */
- public $hierarchical = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $uri->query = null;
-
- // typecode check
- $semicolon_pos = strrpos($uri->path, ';'); // reverse
- if ($semicolon_pos !== false) {
- $type = substr($uri->path, $semicolon_pos + 1); // no semicolon
- $uri->path = substr($uri->path, 0, $semicolon_pos);
- $type_ret = '';
- if (strpos($type, '=') !== false) {
- // figure out whether or not the declaration is correct
- list($key, $typecode) = explode('=', $type, 2);
- if ($key !== 'type') {
- // invalid key, tack it back on encoded
- $uri->path .= '%3B' . $type;
- } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
- $type_ret = ";type=$typecode";
- }
- } else {
- $uri->path .= '%3B' . $type;
- }
- $uri->path = str_replace(';', '%3B', $uri->path);
- $uri->path .= $type_ret;
- }
- return true;
- }
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/http.php b/library/HTMLPurifier/URIScheme/http.php
deleted file mode 100644
index ce69ec438..000000000
--- a/library/HTMLPurifier/URIScheme/http.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-/**
- * Validates http (HyperText Transfer Protocol) as defined by RFC 2616
- */
-class HTMLPurifier_URIScheme_http extends HTMLPurifier_URIScheme
-{
- /**
- * @type int
- */
- public $default_port = 80;
-
- /**
- * @type bool
- */
- public $browsable = true;
-
- /**
- * @type bool
- */
- public $hierarchical = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $uri->userinfo = null;
- return true;
- }
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/https.php b/library/HTMLPurifier/URIScheme/https.php
deleted file mode 100644
index 0e96882db..000000000
--- a/library/HTMLPurifier/URIScheme/https.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-/**
- * Validates https (Secure HTTP) according to http scheme.
- */
-class HTMLPurifier_URIScheme_https extends HTMLPurifier_URIScheme_http
-{
- /**
- * @type int
- */
- public $default_port = 443;
- /**
- * @type bool
- */
- public $secure = true;
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/mailto.php b/library/HTMLPurifier/URIScheme/mailto.php
deleted file mode 100644
index c3a6b602a..000000000
--- a/library/HTMLPurifier/URIScheme/mailto.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-// VERY RELAXED! Shouldn't cause problems, not even Firefox checks if the
-// email is valid, but be careful!
-
-/**
- * Validates mailto (for E-mail) according to RFC 2368
- * @todo Validate the email address
- * @todo Filter allowed query parameters
- */
-
-class HTMLPurifier_URIScheme_mailto extends HTMLPurifier_URIScheme
-{
- /**
- * @type bool
- */
- public $browsable = false;
-
- /**
- * @type bool
- */
- public $may_omit_host = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $uri->userinfo = null;
- $uri->host = null;
- $uri->port = null;
- // we need to validate path against RFC 2368's addr-spec
- return true;
- }
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/news.php b/library/HTMLPurifier/URIScheme/news.php
deleted file mode 100644
index 7490927d6..000000000
--- a/library/HTMLPurifier/URIScheme/news.php
+++ /dev/null
@@ -1,35 +0,0 @@
-<?php
-
-/**
- * Validates news (Usenet) as defined by generic RFC 1738
- */
-class HTMLPurifier_URIScheme_news extends HTMLPurifier_URIScheme
-{
- /**
- * @type bool
- */
- public $browsable = false;
-
- /**
- * @type bool
- */
- public $may_omit_host = true;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $uri->userinfo = null;
- $uri->host = null;
- $uri->port = null;
- $uri->query = null;
- // typecode check needed on path
- return true;
- }
-}
-
-// vim: et sw=4 sts=4
diff --git a/library/HTMLPurifier/URIScheme/nntp.php b/library/HTMLPurifier/URIScheme/nntp.php
deleted file mode 100644
index f211d715e..000000000
--- a/library/HTMLPurifier/URIScheme/nntp.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-/**
- * Validates nntp (Network News Transfer Protocol) as defined by generic RFC 1738
- */
-class HTMLPurifier_URIScheme_nntp extends HTMLPurifier_URIScheme
-{
- /**
- * @type int
- */
- public $default_port = 119;
-
- /**
- * @type bool
- */
- public $browsable = false;
-
- /**
- * @param HTMLPurifier_URI $uri
- * @param HTMLPurifier_Config $config
- * @param HTMLPurifier_Context $context
- * @return bool
- */
- public function doValidate(&$uri, $config, $context)
- {
- $uri->userinfo = null;
- $uri->query = null;
- return true;
- }
-}
-
-// vim: et sw=4 sts=4