Feature #20206 » 10724.diff
t3lib/class.t3lib_befunc.php (working copy) | ||
---|---|---|
return $script;
|
||
}
|
||
/**
|
||
* Checks if a given URL matches the host, TYPO3 is running on.
|
||
*
|
||
* Sites are identical if schema, hostname and (optional) port match.
|
||
*
|
||
* @param string URL to compare with TYPO3 request host
|
||
* @return boolean true if given URL matches this host, otherwise false
|
||
*/
|
||
public static function isAllowedSite($url) {
|
||
$parsedUrl = parse_url($url);
|
||
if ($parsedUrl !== false) {
|
||
$typo3RequestHost = '';
|
||
if ($parsedUrl['scheme']) $typo3RequestHost .= $parsedUrl['scheme'];
|
||
$typo3RequestHost .= '://';
|
||
if ($parsedUrl['host']) $typo3RequestHost .= $parsedUrl['host'];
|
||
if ($parsedUrl['port']) $typo3RequestHost .= ':' . $parsedUrl['port'];
|
||
if (!strcasecmp(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'), $typo3RequestHost)) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
?>
|
t3lib/class.t3lib_div.php (working copy) | ||
---|---|---|
return $output;
|
||
}
|
||
/**
|
||
* Checks if a given string is a Uniform Resource Locator (URL).
|
||
*
|
||
* In deviatiom from RFC 3986, only URLs are successfully identified
|
||
* that have a server component.
|
||
*
|
||
* @param string
|
||
* @return boolean if given string is a URL true, otherwise false
|
||
*/
|
||
public static function isURL($url) {
|
||
$matches = array();
|
||
if (preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $url, $matches)
|
||
&& $matches[4]) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
tests/t3lib/t3lib_befunc_testcase.php (revision 0) | ||
---|---|---|
<?php
|
||
/***************************************************************
|
||
* Copyright notice
|
||
*
|
||
* (c) 2009 Marcus Krause <marcus#expYYYY@t3sec.info>
|
||
* All rights reserved
|
||
*
|
||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||
* free software; you can redistribute it and/or modify
|
||
* it under the terms of the GNU General Public License as published by
|
||
* the Free Software Foundation; either version 2 of the License, or
|
||
* (at your option) any later version.
|
||
*
|
||
* The GNU General Public License can be found at
|
||
* http://www.gnu.org/copyleft/gpl.html.
|
||
*
|
||
* This script is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
* GNU General Public License for more details.
|
||
*
|
||
* This copyright notice MUST APPEAR in all copies of the script!
|
||
***************************************************************/
|
||
/**
|
||
* Testcase for class t3lib_befunc
|
||
*
|
||
* @author Marcus Krause <marcus#expYYYY@t3sec.info>
|
||
* @package TYPO3
|
||
* @subpackage t3lib
|
||
*/
|
||
class t3lib_befunc_testcase extends tx_phpunit_testcase {
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkIsAllowedSite() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
|
||
$this->assertTrue(t3lib_BEfunc::isAllowedSite($testUrl));
|
||
$testUrl = 'http://example.org/';
|
||
$this->assertFalse(t3lib_BEfunc::isAllowedSite($testUrl));
|
||
$testUrl = 'https://www.example.org:443/';
|
||
$this->assertFalse(t3lib_BEfunc::isAllowedSite($testUrl));
|
||
}
|
||
}
|
||
?>
|
tests/t3lib/t3lib_div_testcase.php (working copy) | ||
---|---|---|
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkIsUrl() {
|
||
$testUrl = 'http://www.example.org/';
|
||
$this->assertTrue(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
|
||
$this->assertTrue(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'file://C:\UserName.HostName\Path\file.txt';
|
||
$this->assertTrue(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'telnet://192.0.2.16:80/';
|
||
$this->assertTrue(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
|
||
$this->assertTrue(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'file:///etc/passwd';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = './relpath/file.txt';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = '/abspath/file.txt?arg=value';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'data:text/plain;charset=iso-8859-7,%be%fg%be';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'sip:911@pbx.mycompany.com';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
$testUrl = 'arbitrary string';
|
||
$this->assertFalse(t3lib_div::isUrl($testUrl));
|
||
}
|
||
}
|
||
?>
|