Fix handling of external CSS/JS URLs with query strings

xpressengine/xe-core#2114
This commit is contained in:
Kijin Sung 2017-08-16 23:05:45 +09:00
parent 224410c857
commit 73c09ce876
2 changed files with 11 additions and 2 deletions

View file

@ -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];

View file

@ -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());
});