mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
Add function is_local_url() to check if url is local.
This commit is contained in:
@@ -559,6 +559,14 @@ function z_dns_check($h,$check_mx = 0) {
|
|||||||
return((@dns_get_record($h,$opts) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false);
|
return((@dns_get_record($h,$opts) || filter_var($h, FILTER_VALIDATE_IP)) ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_local_url($url) {
|
||||||
|
if (str_starts_with($url, z_root()) || str_starts_with($url, '/')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Validates a given URL.
|
* @brief Validates a given URL.
|
||||||
*
|
*
|
||||||
|
|||||||
33
tests/unit/includes/NetworkTest.php
Normal file
33
tests/unit/includes/NetworkTest.php
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* tests function from include/network.php
|
||||||
|
*
|
||||||
|
* @package test.util
|
||||||
|
*/
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
require_once('include/network.php');
|
||||||
|
|
||||||
|
class NetworkTest extends TestCase {
|
||||||
|
|
||||||
|
public function setup() : void {
|
||||||
|
\App::set_baseurl("https://mytest.org");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider localUrlTestProvider
|
||||||
|
*/
|
||||||
|
public function testIsLocalURL($url, $expected) {
|
||||||
|
$this->assertEquals($expected, is_local_url($url));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function localUrlTestProvider() : array {
|
||||||
|
return [
|
||||||
|
[ '/some/path', true ],
|
||||||
|
[ 'https://mytest.org/some/path', true ],
|
||||||
|
[ 'https://other.site/some/path', false ],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user