mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 05:37:49 +02:00
Implement URIScheme and subclasses except for mailto. Remove fragment from components, as it is scheme independent.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@218 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -49,7 +49,9 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
||||
$scheme_obj =& $registry->getScheme($scheme, $config);
|
||||
if (!$scheme_obj) return ''; // invalid scheme, clean it out
|
||||
} else {
|
||||
$scheme_obj =& $registry->getScheme($config->get('URI', 'DefaultScheme'), $config);
|
||||
$scheme_obj =& $registry->getScheme(
|
||||
$config->get('URI', 'DefaultScheme'), $config
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,11 +101,8 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
||||
|
||||
// userinfo and host are validated within the regexp
|
||||
|
||||
// regenerate authority
|
||||
$authority =
|
||||
($userinfo === null ? '' : ($userinfo . '@')) .
|
||||
$host .
|
||||
($port === null ? '' : (':' . $port));
|
||||
} else {
|
||||
$port = $host = $userinfo = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,10 +119,21 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
|
||||
|
||||
|
||||
// okay, now we defer execution to the subobject for more processing
|
||||
list($authority, $path, $query, $fragment) =
|
||||
$scheme_obj->validateComponents($authority, $path, $query, $fragment);
|
||||
// note that $fragment is omitted
|
||||
list($userinfo, $host, $port, $path, $query) =
|
||||
$scheme_obj->validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
);
|
||||
|
||||
|
||||
// reconstruct authority
|
||||
$authority = null;
|
||||
if (!is_null($userinfo) || !is_null($host) || !is_null($port)) {
|
||||
$authority = '';
|
||||
if($userinfo !== null) $authority .= $userinfo . '@';
|
||||
$authority .= $host;
|
||||
if($port !== null) $authority .= ':' . $port;
|
||||
}
|
||||
|
||||
// reconstruct the result
|
||||
$result = '';
|
||||
|
@@ -3,8 +3,13 @@
|
||||
class HTMLPurifier_URIScheme
|
||||
{
|
||||
|
||||
function validateComponents($authority, $path, $query, $fragment) {
|
||||
return array($authority, $path, $query, $fragment);
|
||||
var $default_port = null;
|
||||
|
||||
function validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
) {
|
||||
if ($this->default_port == $port) $port = null;
|
||||
return array($userinfo, $host, $port, $path, $query);
|
||||
}
|
||||
|
||||
}
|
||||
|
21
library/HTMLPurifier/URIScheme/ftp.php
Normal file
21
library/HTMLPurifier/URIScheme/ftp.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/URIScheme.php';
|
||||
|
||||
class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme {
|
||||
|
||||
var $default_port = 21;
|
||||
|
||||
function validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
) {
|
||||
list($userinfo, $host, $port, $path, $query) =
|
||||
parent::validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config );
|
||||
// typecode check needed on path
|
||||
return array($userinfo, $host, $port, $path, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -4,8 +4,15 @@ require_once 'HTMLPurifier/URIScheme.php';
|
||||
|
||||
class HTMLPurifier_URIScheme_http extends HTMLPurifier_URIScheme {
|
||||
|
||||
function validateComponents($authority, $path, $query, $fragment) {
|
||||
|
||||
var $default_port = 80;
|
||||
|
||||
function validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
) {
|
||||
list($userinfo, $host, $port, $path, $query) =
|
||||
parent::validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config );
|
||||
return array(null, $host, $port, $path, $query);
|
||||
}
|
||||
|
||||
}
|
||||
|
11
library/HTMLPurifier/URIScheme/https.php
Normal file
11
library/HTMLPurifier/URIScheme/https.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/URIScheme/http.php';
|
||||
|
||||
class HTMLPurifier_URIScheme_https extends HTMLPurifier_URIScheme_http {
|
||||
|
||||
var $default_port = 443;
|
||||
|
||||
}
|
||||
|
||||
?>
|
19
library/HTMLPurifier/URIScheme/news.php
Normal file
19
library/HTMLPurifier/URIScheme/news.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/URIScheme.php';
|
||||
|
||||
class HTMLPurifier_URIScheme_news extends HTMLPurifier_URIScheme {
|
||||
|
||||
function validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
) {
|
||||
list($userinfo, $host, $port, $path, $query) =
|
||||
parent::validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config );
|
||||
// typecode check needed on path
|
||||
return array(null, null, null, $path, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
20
library/HTMLPurifier/URIScheme/nntp.php
Normal file
20
library/HTMLPurifier/URIScheme/nntp.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/URIScheme.php';
|
||||
|
||||
class HTMLPurifier_URIScheme_nntp extends HTMLPurifier_URIScheme {
|
||||
|
||||
var $default_port = 119;
|
||||
|
||||
function validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config
|
||||
) {
|
||||
list($userinfo, $host, $port, $path, $query) =
|
||||
parent::validateComponents(
|
||||
$userinfo, $host, $port, $path, $query, $config );
|
||||
return array(null, $host, $port, $path, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user