Feature #20206 » 10724_v4.diff
t3lib/class.t3lib_div.php (working copy) | ||
---|---|---|
}
|
||
/**
|
||
* Checks if a given URL matches the host that currently handles this HTTP request.
|
||
* Scheme, hostname and (optional) port of the given URL are compared.
|
||
*
|
||
* @param string $url: URL to compare with the TYPO3 request host
|
||
* @return boolean Whether the URL matches the TYPO3 request host
|
||
*/
|
||
public static function isSameHost($url) {
|
||
return (stripos($url . '/', self::getIndpEnv('TYPO3_REQUEST_HOST') . '/') === 0);
|
||
}
|
||
/**
|
||
* Check for item in list
|
||
* Check if an item exists in a comma-separated list of items.
|
||
* Usage: 163
|
||
... | ... | |
return $output;
|
||
}
|
||
/**
|
||
* Checks if a given string is a Uniform Resource Locator (URL).
|
||
*
|
||
* @param string $url: The URL to be validated
|
||
* @return boolean Whether the given URL is valid
|
||
*/
|
||
public static function isValidUrl($url) {
|
||
return (filter_var($url, FILTER_VALIDATE_URL) !== false);
|
||
}
|
||
... | ... | |
/**
|
||
* Returns the maximum upload size for a file that is allowed. Measured in KB.
|
||
* This might be handy to find out the real upload limit that is possible for this
|
||
* This might be handy to find out the real upload limit that is possible for this
|
||
* TYPO3 installation. The first parameter can be used to set something that overrides
|
||
* the maxFileSize, usually for the TCA values.
|
||
*
|
tests/t3lib/t3lib_div_testcase.php (working copy) | ||
---|---|---|
t3lib_div::getBytesFromSizeMeasurement('100g')
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLSucceedsWithWebRessource() {
|
||
$testUrl = 'http://www.example.org/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLSucceedsWithExtentedWebRessource() {
|
||
$testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLSucceedsWithTelnetRessource() {
|
||
$testUrl = 'telnet://192.0.2.16:80/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLSucceedsWithLdapRessource() {
|
||
$testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLSucceedsWithFileRessource() {
|
||
$testUrl = 'file:///etc/passwd';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisValidURLFailsWithHostnameOnly() {
|
||
$testUrl = 'www.example.org/';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostFailsWithLocalhostIPOnly() {
|
||
$testUrl = '127.0.0.1';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostFailsWithPathsOnly() {
|
||
$testUrl = './relpath/file.txt';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
$testUrl = '/abspath/file.txt?arg=value';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostFailsWithArbitraryString() {
|
||
$testUrl = 'arbitrary string';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostFailsWithEmptyUrl() {
|
||
$testUrl = '';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostFailsWithDifferentHost() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
|
||
$this->assertFalse(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkisSameHostSucceedsWithCurrentHost() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
|
||
$this->assertTrue(t3lib_div::isSameHost($testUrl));
|
||
}
|
||
}
|
||
?>
|