mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-25 21:32:51 +09:00
Add unit tests for #429 and improve regexp efficiency
This commit is contained in:
parent
c6ed0bdd28
commit
45d17eb9bb
2 changed files with 11 additions and 3 deletions
|
|
@ -79,7 +79,7 @@ class MediaFilter
|
|||
*/
|
||||
public static function formatPrefix($prefix)
|
||||
{
|
||||
$prefix = preg_match('@^(https?:)?//(.*)$@i', $prefix, $matches) ? $matches[2] : $prefix;
|
||||
$prefix = preg_match('@^(?:https?:)?//(.*)$@i', $prefix, $matches) ? $matches[1] : $prefix;
|
||||
if (strpos($prefix, '/') === false)
|
||||
{
|
||||
$prefix .= '/';
|
||||
|
|
@ -117,7 +117,7 @@ class MediaFilter
|
|||
{
|
||||
$result[] = str_replace('\*\.', '[a-z0-9-]+\.', preg_quote($domain, '%'));
|
||||
}
|
||||
return '%^(https?:)?//(' . implode('|', $result) . ')%';
|
||||
return '%^(?:https?:)?//(' . implode('|', $result) . ')%';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -150,7 +150,7 @@ class MediaFilter
|
|||
{
|
||||
$result[] = str_replace('\*\.', '[a-z0-9-]+\.', preg_quote($domain, '%'));
|
||||
}
|
||||
return '%^(https?:)?//(' . implode('|', $result) . ')%';
|
||||
return '%^(?:https?:)?//(' . implode('|', $result) . ')%';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ class MediaFilterTest extends \Codeception\TestCase\Test
|
|||
$this->assertTrue(Rhymix\Framework\Filters\MediaFilter::matchIframeWhitelist('https://www.youtube.com/v'));
|
||||
$this->assertFalse(Rhymix\Framework\Filters\MediaFilter::matchIframeWhitelist('http://www-youtube.com/v'));
|
||||
|
||||
// Match protocol-relative URLs.
|
||||
$this->assertTrue(Rhymix\Framework\Filters\MediaFilter::matchIframeWhitelist('//www.youtube.com/v'));
|
||||
$this->assertFalse(Rhymix\Framework\Filters\MediaFilter::matchIframeWhitelist('//www-youtube.com/v'));
|
||||
|
||||
// object whitelist as array.
|
||||
$this->assertTrue(in_array('www.youtube.com/', Rhymix\Framework\Filters\MediaFilter::getObjectWhitelist()));
|
||||
$this->assertFalse(in_array('random-website.com/', Rhymix\Framework\Filters\MediaFilter::getObjectWhitelist()));
|
||||
|
|
@ -27,6 +31,10 @@ class MediaFilterTest extends \Codeception\TestCase\Test
|
|||
// Match individual URL against object whitelist.
|
||||
$this->assertTrue(Rhymix\Framework\Filters\MediaFilter::matchObjectWhitelist('https://www.youtube.com/v'));
|
||||
$this->assertFalse(Rhymix\Framework\Filters\MediaFilter::matchObjectWhitelist('http://www-youtube.com/v'));
|
||||
|
||||
// Match protocol-relative URLs.
|
||||
$this->assertTrue(Rhymix\Framework\Filters\MediaFilter::matchObjectWhitelist('//www.youtube.com/v'));
|
||||
$this->assertFalse(Rhymix\Framework\Filters\MediaFilter::matchObjectWhitelist('//www-youtube.com/v'));
|
||||
}
|
||||
|
||||
public function testAddPrefix()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue