Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Requirements acces to files with query strings (fixes #7735)

Originally authored by florian.thoma, tests added
by Ingo Schommer. Also removed query params from
file paths before calling mtime() on it.

See #1023
  • Loading branch information...
commit 618a3d0314e75d8c419055469aff92b888f7395e 1 parent af6ecce
@chillu chillu authored
Showing with 37 additions and 4 deletions.
  1. +28 −0 tests/forms/RequirementsTest.php
  2. +9 −4 view/Requirements.php
View
28 tests/forms/RequirementsTest.php
@@ -325,6 +325,34 @@ public function testJsWriteToBody() {
$this->assertContains('</script></body>', $html);
}
+ public function testSuffix() {
+ $template = '<html><head></head><body><header>My header</header><p>Body</p></body></html>';
+ $basePath = $this->getCurrentRelativePath();
+ $basePath = 'framework' . substr($basePath, strlen(FRAMEWORK_DIR));
+
+ $backend = new Requirements_Backend;
+
+ $backend->javascript($basePath .'/RequirementsTest_a.js');
+ $backend->javascript($basePath .'/RequirementsTest_b.js?foo=bar&bla=blubb');
+ $backend->css($basePath .'/RequirementsTest_a.css');
+ $backend->css($basePath .'/RequirementsTest_b.css?foo=bar&bla=blubb');
+
+ $backend->set_suffix_requirements(true);
+ $html = $backend->includeInHTML(false, $template);
+ $this->assertRegexp('/RequirementsTest_a\.js\?m=[\d]*/', $html);
+ $this->assertRegexp('/RequirementsTest_b\.js\?m=[\d]*&foo=bar&bla=blubb/', $html);
+ $this->assertRegexp('/RequirementsTest_a\.css\?m=[\d]*/', $html);
+ $this->assertRegexp('/RequirementsTest_b\.css\?m=[\d]*&foo=bar&bla=blubb/', $html);
+
+ $backend->set_suffix_requirements(false);
+ $html = $backend->includeInHTML(false, $template);
+ $this->assertNotContains('RequirementsTest_a.js=', $html);
+ $this->assertNotRegexp('/RequirementsTest_a\.js\?m=[\d]*/', $html);
+ $this->assertNotRegexp('/RequirementsTest_b\.js\?m=[\d]*&foo=bar&bla=blubb/', $html);
+ $this->assertNotRegexp('/RequirementsTest_a\.css\?m=[\d]*/', $html);
+ $this->assertNotRegexp('/RequirementsTest_b\.css\?m=[\d]*&foo=bar&bla=blubb/', $html);
+ }
+
public function assertFileIncluded($backend, $type, $files) {
$type = strtolower($type);
switch (strtolower($type)) {
View
13 view/Requirements.php
@@ -790,16 +790,21 @@ protected function path_for_file($fileOrUrl) {
if(preg_match('{^//|http[s]?}', $fileOrUrl)) {
return $fileOrUrl;
} elseif(Director::fileExists($fileOrUrl)) {
+ $filePath = preg_replace('/\?.*/', '', Director::baseFolder() . '/' . $fileOrUrl);
$prefix = Director::baseURL();
$mtimesuffix = "";
$suffix = '';
+ if($this->suffix_requirements) {
+ $mtimesuffix = "?m=" . filemtime($filePath);
+ $suffix = '&';
+ }
if(strpos($fileOrUrl, '?') !== false) {
- $suffix = '?' . substr($fileOrUrl, strpos($fileOrUrl, '?')+1);
+ if (strlen($suffix) == 0) {
+ $suffix = '?';
+ }
+ $suffix .= substr($fileOrUrl, strpos($fileOrUrl, '?')+1);
$fileOrUrl = substr($fileOrUrl, 0, strpos($fileOrUrl, '?'));
}
- if($this->suffix_requirements) {
- $mtimesuffix = "?m=" . filemtime(Director::baseFolder() . '/' . $fileOrUrl);
- }
return "{$prefix}{$fileOrUrl}{$mtimesuffix}{$suffix}";
} else {
return false;

0 comments on commit 618a3d0

Please sign in to comment.
Something went wrong with that request. Please try again.