mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7787 from NightJar/patch-2
FIX: Allow absolute URLs be use as resources
This commit is contained in:
commit
795c07c51d
@ -71,6 +71,9 @@ class SimpleResourceURLGenerator implements ResourceURLGenerator
|
||||
$relativePath = $resource->getRelativePath();
|
||||
$exists = $resource->exists();
|
||||
$absolutePath = $resource->getPath();
|
||||
} elseif (Director::is_absolute_url($relativePath)) {
|
||||
// Path is not relative, and probably not of this site
|
||||
return $relativePath;
|
||||
} else {
|
||||
// Use normal string
|
||||
$absolutePath = preg_replace('/\?.*/', '', Director::baseFolder() . '/' . $relativePath);
|
||||
|
@ -64,4 +64,12 @@ class SimpleResourceURLGeneratorTest extends SapphireTest
|
||||
$generator->urlForResource($module->getResource('client/style.css'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testAbsoluteResource()
|
||||
{
|
||||
/** @var SimpleResourceURLGenerator $generator */
|
||||
$generator = Injector::inst()->get(ResourceURLGenerator::class);
|
||||
$fakeExternalAsset = 'https://cdn.example.com/some_library.css';
|
||||
$this->assertEquals($fakeExternalAsset, $generator->urlForResource($fakeExternalAsset));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user