Merge pull request #230 from catalyst/img-replace-improvement

Issue #229: Updated DOM element matching to allow for "//" urls in images
This commit is contained in:
Brendan Heywood
2021-01-19 10:07:21 +11:00
committed by GitHub
2 changed files with 19 additions and 6 deletions

View File

@@ -44,11 +44,13 @@ defined('MOODLE_INTERNAL') || die();
class maintenance_static_page_io {
/**
* Checks if the given string starts with "http://" or "https://".
* Also checks for "//" at the start of image, which setting_file_url still uses.
*
* @param $url
* @return bool
*/
public static function is_url($url) {
return (bool)preg_match('#^http(s)?://#', $url);
return ((bool) preg_match('#^http(s)?://#', $url) || (bool) preg_match('#^//#', $url));
}
/**

View File

@@ -260,11 +260,22 @@ class maintenance_static_page_test extends auth_outage_base_testcase {
self::assertContains('www.example.com/moodle/auth/outage/file.php?file=img.png', $io->get_url_for_file('img.png'));
}
public function test_is_url() {
self::assertTrue(maintenance_static_page_io::is_url('http://catalyst.net.nz'));
self::assertTrue(maintenance_static_page_io::is_url('https://www.catalyst-au.net/'));
self::assertFalse(maintenance_static_page_io::is_url('/homepage'));
self::assertFalse(maintenance_static_page_io::is_url('file://homepage'));
public function is_url_dataprovider() {
return [
[true, 'http://catalyst.net.nz'],
[true, 'https://www.catalyst-au.net/'],
[false, '/homepage'],
[false, 'file://homepage'],
[true, '//catalyst-au.net/img/test.jpg'],
[false, '://www.catalyst-au.net/img/test.jpg']
];
}
/**
* @dataProvider is_url_dataprovider
*/
public function test_is_url($result, $url) {
self::assertEquals($result, maintenance_static_page_io::is_url($url));
}
public function test_file_get_data() {