Feature #20206 » 10724_v2.diff
tests/t3lib/t3lib_div_testcase.php (Arbeitskopie) | ||
---|---|---|
$this->assertEquals($expectedArray, $actualArray);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkIsValidUrl() {
|
||
$testUrl = 'http://www.example.org/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'telnet://192.0.2.16:80/';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'file:///etc/passwd';
|
||
$this->assertTrue(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'www.example.org/';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = '127.0.0.1';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = './relpath/file.txt';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = '/abspath/file.txt?arg=value';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
$testUrl = 'arbitrary string';
|
||
$this->assertFalse(t3lib_div::isValidUrl($testUrl));
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function checkIsAllowedUrl() {
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
|
||
$this->assertTrue(t3lib_div::isAllowedUrl($testUrl));
|
||
$testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.external.domain.org';
|
||
$this->assertFalse(t3lib_div::isAllowedUrl($testUrl));
|
||
$testUrl = 'http://example.org/';
|
||
$this->assertFalse(t3lib_div::isAllowedUrl($testUrl));
|
||
$testUrl = 'https://www.example.org:443/';
|
||
$this->assertFalse(t3lib_div::isAllowedUrl($testUrl));
|
||
}
|
||
}
|
||
?>
|
t3lib/class.t3lib_div.php (Arbeitskopie) | ||
---|---|---|
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);
|
||
}
|
||
... | ... | |
/*************************
|
||
*
|
||
* ARRAY FUNCTIONS
|
||
... | ... | |
}
|
||
/**
|
||
* 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 isAllowedUrl($url) {
|
||
return (stripos($url . '/', self::getIndpEnv('TYPO3_REQUEST_HOST') . '/') === 0);
|
||
}
|
||
/**
|
||
* Verifies the input filename againts the 'fileDenyPattern'. Returns true if OK.
|
||
* Usage: 2
|
||
*
|