From 93a0122c0f61b487cf0cc9d010913e3cdf655597 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 12 Sep 2016 17:25:08 +1200 Subject: [PATCH] =?UTF-8?q?FIX:=20Don=E2=80=99t=20treat=20URLs=20as=20root?= =?UTF-8?q?=20relative=20when=20FRAMEWORK=5FDIR=20=3D=20=E2=80=9C=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code was assuming that FRAMEWORK_DIR would always have a value. If it doesn’t (because you’re running a test instance of a naked framework) This caused URLs to be treated as root relative, which creates some duplicate-inclusion bugs. The use of ltrim() works, but is a bit clumsy. A more flexible approach to including front-end assets of given modules would be preferable; ideally something that also let you keep your code outside of the web root. --- Forms/GridField/GridFieldPrintButton.php | 2 +- Forms/HTMLEditor/HTMLEditorField_Toolbar.php | 2 +- Forms/UploadField_ItemHandler.php | 2 +- Forms/UploadField_SelectHandler.php | 2 +- admin/code/LeftAndMain.php | 10 +++++----- admin/code/MemberImportForm.php | 2 +- admin/code/SecurityAdmin.php | 12 ++++++------ tests/control/HTTPTest.php | 3 ++- tests/core/ClassInfoTest.php | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Forms/GridField/GridFieldPrintButton.php b/Forms/GridField/GridFieldPrintButton.php index d4d753a78..9b7ae787c 100644 --- a/Forms/GridField/GridFieldPrintButton.php +++ b/Forms/GridField/GridFieldPrintButton.php @@ -119,7 +119,7 @@ class GridFieldPrintButton implements GridField_HTMLProvider, GridField_ActionPr public function handlePrint($gridField, $request = null) { set_time_limit(60); Requirements::clear(); - Requirements::css(FRAMEWORK_DIR . '/client/dist/styles/GridField_print.css'); + Requirements::css(ltrim(FRAMEWORK_DIR . '/client/dist/styles/GridField_print.css', '/')); if($data = $this->generatePrintData($gridField)){ return $data->renderWith(get_class($gridField)."_print"); diff --git a/Forms/HTMLEditor/HTMLEditorField_Toolbar.php b/Forms/HTMLEditor/HTMLEditorField_Toolbar.php index cc43df8cf..2bea2dd10 100644 --- a/Forms/HTMLEditor/HTMLEditorField_Toolbar.php +++ b/Forms/HTMLEditor/HTMLEditorField_Toolbar.php @@ -250,7 +250,7 @@ class HTMLEditorField_Toolbar extends RequestHandler $remoteURL->addExtraClass('remoteurl'); $fromWeb->addExtraClass('content ss-uploadfield htmleditorfield-from-web'); - Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/AssetUploadField.css'); + Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/AssetUploadField.css', '/')); $computerUploadField = UploadField::create('AssetUploadField', ''); $computerUploadField->setConfig('previewMaxWidth', 40); $computerUploadField->setConfig('previewMaxHeight', 30); diff --git a/Forms/UploadField_ItemHandler.php b/Forms/UploadField_ItemHandler.php index 151d07bd4..5ad9dc2f6 100644 --- a/Forms/UploadField_ItemHandler.php +++ b/Forms/UploadField_ItemHandler.php @@ -147,7 +147,7 @@ class UploadField_ItemHandler extends RequestHandler return $this->httpError(403); } - Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/UploadField.css'); + Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/UploadField.css', '/')); return $this->customise(array( 'Form' => $this->EditForm() diff --git a/Forms/UploadField_SelectHandler.php b/Forms/UploadField_SelectHandler.php index f1014302a..7df08fc12 100644 --- a/Forms/UploadField_SelectHandler.php +++ b/Forms/UploadField_SelectHandler.php @@ -60,7 +60,7 @@ class UploadField_SelectHandler extends RequestHandler public function index() { // Requires a separate JS file, because we can't reach into the iframe with entwine. - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/UploadField_select.js'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/UploadField_select.js', '/')); return $this->renderWith('SilverStripe\\Admin\\CMSDialog'); } diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index 09be46df5..9b7a5df54 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -165,7 +165,7 @@ class LeftAndMain extends Controller implements PermissionProvider { * @var array */ private static $admin_themes = [ - '/framework/admin/themes/cms-forms', + 'silverstripe/framework:/admin/themes/cms-forms', SSViewer::DEFAULT_THEME, ]; @@ -536,12 +536,12 @@ class LeftAndMain extends Controller implements PermissionProvider { window.ss.config = " . $this->getCombinedClientConfig() . "; "); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js'); - Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/')); + Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/')); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-legacy.js'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-legacy.js', '/')); - Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/client/lang', false, true); + Requirements::add_i18n_javascript(ltrim(FRAMEWORK_DIR . '/client/lang', '/'), false, true); Requirements::add_i18n_javascript(FRAMEWORK_ADMIN_DIR . '/client/lang', false, true); if ($this->config()->session_keepalive_ping) { diff --git a/admin/code/MemberImportForm.php b/admin/code/MemberImportForm.php index 6f170f650..3b844a956 100644 --- a/admin/code/MemberImportForm.php +++ b/admin/code/MemberImportForm.php @@ -71,7 +71,7 @@ class MemberImportForm extends Form { parent::__construct($controller, $name, $fields, $actions, $validator); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/')); Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js'); Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css'); diff --git a/admin/code/SecurityAdmin.php b/admin/code/SecurityAdmin.php index f03108cf2..82351fb48 100755 --- a/admin/code/SecurityAdmin.php +++ b/admin/code/SecurityAdmin.php @@ -233,9 +233,9 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { public function memberimport() { Requirements::clear(); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js'); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js'); - Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/')); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js', '/')); + Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/')); return $this->renderWith('BlankPage', array( 'Form' => $this->MemberImportForm()->forTemplate(), @@ -267,9 +267,9 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { public function groupimport() { Requirements::clear(); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js'); - Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js'); - Requirements::css(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css'); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/bundle-lib.js', '/')); + Requirements::javascript(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberImportForm.js', '/')); + Requirements::css(ltrim(FRAMEWORK_ADMIN_DIR . '/client/dist/styles/bundle.css', '/')); return $this->renderWith('BlankPage', array( 'Content' => ' ', diff --git a/tests/control/HTTPTest.php b/tests/control/HTTPTest.php index 2b010c0f5..f0c6ed9b3 100644 --- a/tests/control/HTTPTest.php +++ b/tests/control/HTTPTest.php @@ -327,8 +327,9 @@ class HTTPTest extends FunctionalTest { public function testFilename2url() { $this->withBaseURL('http://www.silverstripe.org/', function($test) { + $frameworkTests = ltrim(FRAMEWORK_DIR . '/tests', '/'); $test->assertEquals( - 'http://www.silverstripe.org/framework/tests/control/HTTPTest.php', + "http://www.silverstripe.org/$frameworkTests/control/HTTPTest.php", HTTP::filename2url(__FILE__) ); }); diff --git a/tests/core/ClassInfoTest.php b/tests/core/ClassInfoTest.php index 115f62c15..ba84fae87 100644 --- a/tests/core/ClassInfoTest.php +++ b/tests/core/ClassInfoTest.php @@ -78,7 +78,7 @@ class ClassInfoTest extends SapphireTest { //$baseFolder = Director::baseFolder() . '/' . FRAMEWORK_DIR . '/tests/_ClassInfoTest'; //$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder); - $classes = ClassInfo::classes_for_folder(FRAMEWORK_DIR . '/tests'); + $classes = ClassInfo::classes_for_folder(ltrim(FRAMEWORK_DIR . '/tests', '/')); $this->assertContains( 'classinfotest', $classes,