Version 3.4.6
This commit is contained in:
1 parent
e4478369d8
commit
b45ea0dffb
1568 files changed
+155104
-161665
No files matched your search
@@ -1,102 +1,101 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
|
||||
*/
|
||||
class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
|
||||
{
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
|
||||
*/
|
||||
protected $ipv4;
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
|
||||
*/
|
||||
protected $ipv6;
|
||||
|
||||
public function __construct() {
|
||||
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
|
||||
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
|
||||
}
|
||||
|
||||
public function validate($string, $config, $context) {
|
||||
$length = strlen($string);
|
||||
// empty hostname is OK; it's usually semantically equivalent:
|
||||
// the default host as defined by a URI scheme is used:
|
||||
//
|
||||
// If the URI scheme defines a default for host, then that
|
||||
// default applies when the host subcomponent is undefined
|
||||
// or when the registered name is empty (zero length).
|
||||
if ($string === '') return '';
|
||||
if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
|
||||
//IPv6
|
||||
$ip = substr($string, 1, $length - 2);
|
||||
$valid = $this->ipv6->validate($ip, $config, $context);
|
||||
if ($valid === false) return false;
|
||||
return '['. $valid . ']';
|
||||
}
|
||||
|
||||
// need to do checks on unusual encodings too
|
||||
$ipv4 = $this->ipv4->validate($string, $config, $context);
|
||||
if ($ipv4 !== false) return $ipv4;
|
||||
|
||||
// A regular domain name.
|
||||
|
||||
// This doesn't match I18N domain names, but we don't have proper IRI support,
|
||||
// so force users to insert Punycode.
|
||||
|
||||
// The productions describing this are:
|
||||
$a = '[a-z]'; // alpha
|
||||
$an = '[a-z0-9]'; // alphanum
|
||||
$and = '[a-z0-9-]'; // alphanum | "-"
|
||||
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
||||
$domainlabel = "$an($and*$an)?";
|
||||
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
||||
$toplabel = "$a($and*$an)?";
|
||||
// hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
$uni=(IPS_DOC_CHAR_SET=="UTF-8")?"u":"";
|
||||
if (preg_match("/^($domainlabel\.)*$toplabel\.?$/i".$uni, $string)) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
// If we have Net_IDNA2 support, we can support IRIs by
|
||||
// punycoding them. (This is the most portable thing to do,
|
||||
// since otherwise we have to assume browsers support
|
||||
|
||||
if ($config->get('Core.EnableIDNA')) {
|
||||
$idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
|
||||
// we need to encode each period separately
|
||||
$parts = explode('.', $string);
|
||||
try {
|
||||
$new_parts = array();
|
||||
foreach ($parts as $part) {
|
||||
$encodable = false;
|
||||
for ($i = 0, $c = strlen($part); $i < $c; $i++) {
|
||||
if (ord($part[$i]) > 0x7a) {
|
||||
$encodable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$encodable) {
|
||||
$new_parts[] = $part;
|
||||
} else {
|
||||
$new_parts[] = $idna->encode($part);
|
||||
}
|
||||
}
|
||||
$string = implode('.', $new_parts);
|
||||
if (preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
|
||||
return $string;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// XXX error reporting
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
|
||||
*/
|
||||
class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
|
||||
{
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
|
||||
*/
|
||||
protected $ipv4;
|
||||
|
||||
/**
|
||||
* Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
|
||||
*/
|
||||
protected $ipv6;
|
||||
|
||||
public function __construct() {
|
||||
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
|
||||
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
|
||||
}
|
||||
|
||||
public function validate($string, $config, $context) {
|
||||
$length = strlen($string);
|
||||
// empty hostname is OK; it's usually semantically equivalent:
|
||||
// the default host as defined by a URI scheme is used:
|
||||
//
|
||||
// If the URI scheme defines a default for host, then that
|
||||
// default applies when the host subcomponent is undefined
|
||||
// or when the registered name is empty (zero length).
|
||||
if ($string === '') return '';
|
||||
if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
|
||||
//IPv6
|
||||
$ip = substr($string, 1, $length - 2);
|
||||
$valid = $this->ipv6->validate($ip, $config, $context);
|
||||
if ($valid === false) return false;
|
||||
return '['. $valid . ']';
|
||||
}
|
||||
|
||||
// need to do checks on unusual encodings too
|
||||
$ipv4 = $this->ipv4->validate($string, $config, $context);
|
||||
if ($ipv4 !== false) return $ipv4;
|
||||
|
||||
// A regular domain name.
|
||||
|
||||
// This doesn't match I18N domain names, but we don't have proper IRI support,
|
||||
// so force users to insert Punycode.
|
||||
|
||||
// The productions describing this are:
|
||||
$a = '[a-z]'; // alpha
|
||||
$an = '[a-z0-9]'; // alphanum
|
||||
$and = '[a-z0-9-]'; // alphanum | "-"
|
||||
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
||||
$domainlabel = "$an($and*$an)?";
|
||||
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
||||
$toplabel = "$a($and*$an)?";
|
||||
// hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
if (preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
// If we have Net_IDNA2 support, we can support IRIs by
|
||||
// punycoding them. (This is the most portable thing to do,
|
||||
// since otherwise we have to assume browsers support
|
||||
|
||||
if ($config->get('Core.EnableIDNA')) {
|
||||
$idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
|
||||
// we need to encode each period separately
|
||||
$parts = explode('.', $string);
|
||||
try {
|
||||
$new_parts = array();
|
||||
foreach ($parts as $part) {
|
||||
$encodable = false;
|
||||
for ($i = 0, $c = strlen($part); $i < $c; $i++) {
|
||||
if (ord($part[$i]) > 0x7a) {
|
||||
$encodable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$encodable) {
|
||||
$new_parts[] = $part;
|
||||
} else {
|
||||
$new_parts[] = $idna->encode($part);
|
||||
}
|
||||
}
|
||||
$string = implode('.', $new_parts);
|
||||
if (preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string)) {
|
||||
return $string;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// XXX error reporting
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
@@ -333,7 +333,7 @@ class HTMLPurifier_Encoder
|
||||
/**
|
||||
* Converts a string to UTF-8 based on configuration.
|
||||
*/
|
||||
public static function convertToUTF8($str, $config, $context) {
|
||||
public static function convertToUTF8($str, $config, $context) {
|
||||
$encoding = $config->get('Core.Encoding');
|
||||
if ($encoding === 'utf-8') return $str;
|
||||
static $iconv = null;
|
||||
@@ -355,6 +355,10 @@ class HTMLPurifier_Encoder
|
||||
$str = utf8_encode($str);
|
||||
return $str;
|
||||
}
|
||||
else
|
||||
{
|
||||
return IPSText::convertCharsets( $str, $encoding );
|
||||
}
|
||||
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,99 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Injector that converts http, https and ftp text URLs to actual links.
|
||||
*/
|
||||
class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
|
||||
{
|
||||
|
||||
public $name = 'Linkify';
|
||||
public $needed = array('a' => array('href'));
|
||||
|
||||
public function handleText(&$token) {
|
||||
if (!$this->allowsElement('a')) return;
|
||||
|
||||
if (strpos($token->data, '://') === false) {
|
||||
// our really quick heuristic failed, abort
|
||||
// this may not work so well if we want to match things like
|
||||
// "google.com", but then again, most people don't
|
||||
return;
|
||||
}
|
||||
//print $token->data;
|
||||
// there is/are URL(s). Let's split the string:
|
||||
// Note: this regex is extremely permissive
|
||||
//$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
/* MODIFIED April 26, 2013
|
||||
@link http://community.invisionpower.com/resources/bugs.html/_/ip-board/links-being-corrupted-or-malformed-in-board-and-nexus-r41993
|
||||
Test case:
|
||||
http://invisionpower.com,
|
||||
http://invisionpower.com.
|
||||
http://invisionpower.com
|
||||
https://invisionpower.com
|
||||
https://blah.gov/blah-blah.as
|
||||
http://en.wikipedia.org/wiki/Chi_(mythology)
|
||||
(http://google.com)
|
||||
*/
|
||||
$uni=(IPS_DOC_CHAR_SET=="UTF-8")?"u":"";
|
||||
preg_match_all( "#(.*?)(\()?((?:http|ftp|https):\/\/[\p{L}\-_]+(?:\.[\p{L}\-_]+)?(?:[\p{L}\-\.,\(\)@?^=%&:\/~\+\#]*[\p{L}\-\@?^=%&\/~\+\#]))(.*?)$#ims" . $uni, $token->data, $matches );
|
||||
//print_r($matches);exit;
|
||||
|
||||
//$token = array();
|
||||
|
||||
// $i = index
|
||||
// $c = count
|
||||
// $l = is link
|
||||
/*for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
|
||||
if (!$l) {
|
||||
if ($bits[$i] === '') continue;
|
||||
$token[] = new HTMLPurifier_Token_Text($bits[$i]);
|
||||
} else {
|
||||
$token[] = new HTMLPurifier_Token_Start('a', array('href' => $bits[$i]));
|
||||
$token[] = new HTMLPurifier_Token_Text($bits[$i]);
|
||||
$token[] = new HTMLPurifier_Token_End('a');
|
||||
}
|
||||
}*/
|
||||
|
||||
if( is_array($matches) AND count($matches) )
|
||||
{
|
||||
$token = array();//by denchu 06062013
|
||||
foreach( $matches[0] as $k => $match )
|
||||
{
|
||||
if( !$matches[3][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($token->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $matches[1][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[1][$k]);
|
||||
}
|
||||
|
||||
if( $matches[2][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[2][$k]);
|
||||
}
|
||||
|
||||
if( !$matches[2][$k] AND $matches[4][$k] == ')' )
|
||||
{
|
||||
$matches[3][$k] .= ')';
|
||||
unset($matches[4][$k]);
|
||||
}
|
||||
|
||||
$token[] = new HTMLPurifier_Token_Start('a', array('href' => $matches[3][$k]));
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[3][$k]);
|
||||
$token[] = new HTMLPurifier_Token_End('a');
|
||||
|
||||
if( $matches[4][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[4][$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//print_r($token);exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Injector that converts http, https and ftp text URLs to actual links.
|
||||
*/
|
||||
class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
|
||||
{
|
||||
|
||||
public $name = 'Linkify';
|
||||
public $needed = array('a' => array('href'));
|
||||
|
||||
public function handleText(&$token) {
|
||||
if (!$this->allowsElement('a')) return;
|
||||
|
||||
//var_dump( $token->data ); exit;
|
||||
|
||||
if (strpos($token->data, '://') === false) {
|
||||
// our really quick heuristic failed, abort
|
||||
// this may not work so well if we want to match things like
|
||||
// "google.com", but then again, most people don't
|
||||
return;
|
||||
}
|
||||
//print $token->data;
|
||||
// there is/are URL(s). Let's split the string:
|
||||
// Note: this regex is extremely permissive
|
||||
//$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
/* MODIFIED April 26, 2013
|
||||
@link http://community.invisionpower.com/resources/bugs.html/_/ip-board/links-being-corrupted-or-malformed-in-board-and-nexus-r41993
|
||||
Test case:
|
||||
http://invisionpower.com,
|
||||
http://invisionpower.com.
|
||||
http://invisionpower.com
|
||||
https://invisionpower.com
|
||||
https://blah.gov/blah-blah.as
|
||||
http://en.wikipedia.org/wiki/Chi_(mythology)
|
||||
http://en.wikipedia.org/wiki/Assassin's_Creed
|
||||
(http://google.com)
|
||||
*/
|
||||
|
||||
preg_match_all( "#(.*?)(\()?((?:http|ftp|https):\/\/[\w\-_]+(?:\.[\w\-_]+)?(?:[\w\-\.,\'\(\)@?^=%&:/~\+\#]*[\w\-\@?^=%&/~\+\#]))(.*)(?(?=\S+)\S+)(.*)$#ims", $token->data, $matches );
|
||||
|
||||
//$token = array();
|
||||
|
||||
// $i = index
|
||||
// $c = count
|
||||
// $l = is link
|
||||
/*for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
|
||||
if (!$l) {
|
||||
if ($bits[$i] === '') continue;
|
||||
$token[] = new HTMLPurifier_Token_Text($bits[$i]);
|
||||
} else {
|
||||
$token[] = new HTMLPurifier_Token_Start('a', array('href' => $bits[$i]));
|
||||
$token[] = new HTMLPurifier_Token_Text($bits[$i]);
|
||||
$token[] = new HTMLPurifier_Token_End('a');
|
||||
}
|
||||
}*/
|
||||
if( is_array($matches[0]) AND count($matches[0]) )
|
||||
{
|
||||
$token = array();
|
||||
|
||||
foreach( $matches[0] as $k => $match )
|
||||
{
|
||||
if( !$matches[3][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($token->data);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $matches[1][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[1][$k]);
|
||||
}
|
||||
|
||||
if( $matches[2][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[2][$k]);
|
||||
}
|
||||
|
||||
if( !$matches[2][$k] AND !in_array( $matches[4][$k], array( '!', '.', ',' ) ) AND strpos( $matches[4][$k], ' ' ) === false AND ! preg_match( "#(\r|\n|\r\n)#i", $matches[4][$k] ) )
|
||||
{
|
||||
$matches[3][$k] .= $matches[4][$k];
|
||||
unset($matches[4][$k]);
|
||||
}
|
||||
|
||||
$token[] = new HTMLPurifier_Token_Start('a', array('href' => str_replace( '\'', '%27', $matches[3][$k] )));
|
||||
$token[] = new HTMLPurifier_Token_Text($matches[3][$k]);
|
||||
$token[] = new HTMLPurifier_Token_End('a');
|
||||
|
||||
if( $matches[4][$k] )
|
||||
{
|
||||
// Let's do some testing. We may need to recurse in on this line for extra links.
|
||||
$test = explode( ' ', $matches[4][$k] );
|
||||
foreach( $test AS $v )
|
||||
{
|
||||
if ( strpos( $v, 'http' ) !== false OR strpos( $v, 'https' ) !== false OR strpos( $v, 'ftp' ) !== false )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Start('a', array('href' => str_replace( '\'', '%27', $v )));
|
||||
$token[] = new HTMLPurifier_Token_Text($v);
|
||||
$token[] = new HTMLPurifier_Token_End('a');
|
||||
$token[] = new HTMLPurifier_Token_Text(' '); // Because we exploded the text, spaces were lost. Re-add them.
|
||||
}
|
||||
else
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text($v);
|
||||
$token[] = new HTMLPurifier_Token_Text(' '); // Because we exploded the text, spaces were lost. Re-add them.
|
||||
}
|
||||
}
|
||||
//$token[] = new HTMLPurifier_Token_Text($matches[4][$k]);
|
||||
}
|
||||
|
||||
if( $matches[5][$k] )
|
||||
{
|
||||
$token[] = new HTMLPurifier_Token_Text( $matches[5][$k] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
@@ -5,6 +5,6 @@
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com/">IP.Board</a>
|
||||
IP.Board
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user