mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Fix requirements tests
This commit is contained in:
parent
5ffe64f024
commit
f4a77649a4
@ -84,7 +84,7 @@ class ModuleResourceLoader implements TemplateGlobalProvider
|
|||||||
protected function resolveModuleResource($resource)
|
protected function resolveModuleResource($resource)
|
||||||
{
|
{
|
||||||
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
|
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
|
||||||
if (!preg_match('#(?<module>[^/: ]*/[^/: ]*) *: *(?<resource>[^ ]*)#', $resource, $matches)) {
|
if (!preg_match('#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#', $resource, $matches)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$module = $matches['module'];
|
$module = $matches['module'];
|
||||||
|
@ -818,20 +818,19 @@ class RequirementsTest extends SapphireTest
|
|||||||
public function testCommentedOutScriptTagIsIgnored()
|
public function testCommentedOutScriptTagIsIgnored()
|
||||||
{
|
{
|
||||||
/// Disable nonce
|
/// Disable nonce
|
||||||
Injector::inst()->registerService(new SimpleResourceURLGenerator(), ResourceURLGenerator::class);
|
$urlGenerator = new SimpleResourceURLGenerator();
|
||||||
|
Injector::inst()->registerService($urlGenerator, ResourceURLGenerator::class);
|
||||||
|
|
||||||
$template = '<html><head></head><body><!--<script>alert("commented out");</script>-->'
|
$template = '<html><head></head><body><!--<script>alert("commented out");</script>-->'
|
||||||
. '<h1>more content</h1></body></html>';
|
. '<h1>more content</h1></body></html>';
|
||||||
/**
|
/** @var Requirements_Backend $backend */
|
||||||
* @var Requirements_Backend $backend
|
|
||||||
*/
|
|
||||||
$backend = Injector::inst()->create(Requirements_Backend::class);
|
$backend = Injector::inst()->create(Requirements_Backend::class);
|
||||||
$this->setupRequirements($backend);
|
$this->setupRequirements($backend);
|
||||||
|
|
||||||
$src = $this->getThemeRoot() . '/javascript/RequirementsTest_a.js';
|
$src = $this->getThemeRoot() . '/javascript/RequirementsTest_a.js';
|
||||||
$urlSrc = Controller::join_links(Director::baseURL(), $src);
|
|
||||||
$backend->javascript($src);
|
$backend->javascript($src);
|
||||||
$html = $backend->includeInHTML($template);
|
$html = $backend->includeInHTML($template);
|
||||||
|
$urlSrc = $urlGenerator->urlForResource($src);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'<html><head></head><body><!--<script>alert("commented out");</script>-->'
|
'<html><head></head><body><!--<script>alert("commented out");</script>-->'
|
||||||
. '<h1>more content</h1><script type="application/javascript" src="' . $urlSrc
|
. '<h1>more content</h1><script type="application/javascript" src="' . $urlSrc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user