From 73c09ce876a4205d5259ed587aff38706b44b9a2 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 16 Aug 2017 23:05:45 +0900 Subject: [PATCH] Fix handling of external CSS/JS URLs with query strings xpressengine/xe-core#2114 --- classes/frontendfile/FrontEndFileHandler.class.php | 6 +++++- tests/unit/classes/FrontEndFileHandlerTest.php | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/frontendfile/FrontEndFileHandler.class.php b/classes/frontendfile/FrontEndFileHandler.class.php index 30bc68ab9..aa037c506 100644 --- a/classes/frontendfile/FrontEndFileHandler.class.php +++ b/classes/frontendfile/FrontEndFileHandler.class.php @@ -177,7 +177,11 @@ class FrontEndFileHandler extends Handler $file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']); $file->fileRealPath = FileHandler::getRealPath($pathInfo['dirname']); $file->fileFullPath = $file->fileRealPath . '/' . $pathInfo['basename']; - $file->fileExtension = strtolower($pathInfo['extension']); + $file->fileExtension = strtolower($pathInfo['extension']); + if (($pos = strpos($file->fileExtension, '?')) !== false) + { + $file->fileExtension = substr($file->fileExtension, 0, $pos); + } if (preg_match('/^(.+)\.min$/', $pathInfo['filename'], $matches)) { $file->fileNameNoExt = $matches[1]; diff --git a/tests/unit/classes/FrontEndFileHandlerTest.php b/tests/unit/classes/FrontEndFileHandlerTest.php index 6a9a976e9..9e94d5c33 100644 --- a/tests/unit/classes/FrontEndFileHandlerTest.php +++ b/tests/unit/classes/FrontEndFileHandlerTest.php @@ -30,8 +30,9 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $this->specify("js (body)", function() { $handler = new FrontEndFileHandler(); + $handler->loadFile(array('./common/js/xml_handler.js', 'body')); $handler->loadFile(array('./common/js/xml_js_filter.js', 'head')); - $expected = array(); + $expected[] = array('file' => '/rhymix/common/js/xml_handler.js' . $this->_filemtime('common/js/xml_handler.js'), 'targetie' => null); $this->assertEquals($expected, $handler->getJsFileList('body')); }); @@ -220,9 +221,11 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler = new FrontEndFileHandler(); $handler->loadFile(array('http://external.host/css/style1.css')); $handler->loadFile(array('https://external.host/css/style2.css')); + $handler->loadFile(array('https://external.host/css/style3.css?foo=bar&t=123')); $expected[] = array('file' => 'http://external.host/css/style1.css', 'media'=>'all', 'targetie' => null); $expected[] = array('file' => 'https://external.host/css/style2.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => 'https://external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); $this->assertEquals($expected, $handler->getCssFileList()); }); @@ -230,9 +233,11 @@ class FrontEndFileHandlerTest extends \Codeception\TestCase\Test $handler = new FrontEndFileHandler(); $handler->loadFile(array('//external.host/css/style.css')); $handler->loadFile(array('///external.host/css2/style2.css')); + $handler->loadFile(array('//external.host/css/style3.css?foo=bar&t=123')); $expected[] = array('file' => '//external.host/css/style.css', 'media'=>'all', 'targetie' => null); $expected[] = array('file' => '//external.host/css2/style2.css', 'media'=>'all', 'targetie' => null); + $expected[] = array('file' => '//external.host/css/style3.css?foo=bar&t=123', 'media'=>'all', 'targetie' => null); $this->assertEquals($expected, $handler->getCssFileList()); });