Skip to content
Snippets Groups Projects
Commit 7dcf2efe authored by Demian Katz's avatar Demian Katz
Browse files

Parse URLs in theme.config.php js/css correctly.

- Resolves VUFIND-1200.
parent f3675437
No related merge requests found
...@@ -68,6 +68,27 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper ...@@ -68,6 +68,27 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper
$this->addScripts(); $this->addScripts();
} }
/**
* Given a colon-delimited configuration string, break it apart, making sure
* that URLs in the first position are not inappropriately split.
*
* @param string $current Setting to parse
*
* @return array
*/
protected function parseSetting($current)
{
$parts = explode(':', $current);
// Special case: don't explode URLs:
if (($parts[0] === 'http' || $parts[0] === 'https')
&& '//' === substr($parts[1], 0, 2)
) {
$protocol = array_shift($parts);
$parts[0] = $protocol . ':' . $parts[0];
}
return $parts;
}
/** /**
* Add meta tags to header. * Add meta tags to header.
* *
...@@ -101,7 +122,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper ...@@ -101,7 +122,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper
// Load CSS (make sure we prepend them in the appropriate order; theme // Load CSS (make sure we prepend them in the appropriate order; theme
// resources should load before extras added by individual templates): // resources should load before extras added by individual templates):
foreach (array_reverse($this->container->getCss()) as $current) { foreach (array_reverse($this->container->getCss()) as $current) {
$parts = explode(':', $current); $parts = $this->parseSetting($current);
$headLink()->prependStylesheet( $headLink()->prependStylesheet(
trim($parts[0]), trim($parts[0]),
isset($parts[1]) ? trim($parts[1]) : 'all', isset($parts[1]) ? trim($parts[1]) : 'all',
...@@ -112,7 +133,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper ...@@ -112,7 +133,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper
// Compile and load LESS (make sure we prepend them in the appropriate order // Compile and load LESS (make sure we prepend them in the appropriate order
// theme resources should load before extras added by individual templates): // theme resources should load before extras added by individual templates):
foreach (array_reverse($this->container->getLessCss()) as $current) { foreach (array_reverse($this->container->getLessCss()) as $current) {
$parts = explode(':', $current); $parts = $this->parseSetting($current);
$headLink()->prependStylesheet( $headLink()->prependStylesheet(
$headLink()->addLessStylesheet(trim($parts[0])), $headLink()->addLessStylesheet(trim($parts[0])),
isset($parts[1]) ? trim($parts[1]) : 'all', isset($parts[1]) ? trim($parts[1]) : 'all',
...@@ -141,7 +162,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper ...@@ -141,7 +162,7 @@ class HeadThemeResources extends \Zend\View\Helper\AbstractHelper
// Load Javascript (same ordering considerations as CSS, above): // Load Javascript (same ordering considerations as CSS, above):
$headScript = $this->getView()->plugin('headscript'); $headScript = $this->getView()->plugin('headscript');
foreach (array_reverse($this->container->getJs()) as $current) { foreach (array_reverse($this->container->getJs()) as $current) {
$parts = explode(':', $current); $parts = $this->parseSetting($current);
$headScript()->prependFile( $headScript()->prependFile(
trim($parts[0]), trim($parts[0]),
'text/javascript', 'text/javascript',
......
...@@ -51,6 +51,25 @@ class HeadThemeResourcesTest extends \VuFindTest\Unit\TestCase ...@@ -51,6 +51,25 @@ class HeadThemeResourcesTest extends \VuFindTest\Unit\TestCase
$helper->__invoke(); $helper->__invoke();
} }
/**
* Test configuration parsing.
*
* @return void
*/
public function testConfigParsing()
{
$helper = new HeadThemeResources($this->getResourceContainer());
$tests = [
'foo:bar:baz' => ['foo', 'bar', 'baz'],
'http://foo/bar:baz:xyzzy' => ['http://foo/bar', 'baz', 'xyzzy']
];
foreach ($tests as $test => $expected) {
$this->assertEquals(
$expected, $this->callMethod($helper, 'parseSetting', [$test])
);
}
}
/** /**
* Get a populated resource container for testing. * Get a populated resource container for testing.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment