From 1681ec61241b67696f2e7981c18b2c2a7c5929a0 Mon Sep 17 00:00:00 2001 From: Lukas Erni Date: Sun, 27 Oct 2024 20:15:29 +0100 Subject: [PATCH] Remove default type in script tag and replace application/javascript with text/javascript --- _config/mimetypes.yml | 2 +- src/Control/HTTPResponse.php | 2 +- src/Security/CMSSecurity.php | 2 +- .../MemberAuthenticator/CMSLoginHandler.php | 2 +- src/View/Requirements_Backend.php | 4 ++-- tests/php/Core/ConvertTest.php | 4 ++-- tests/php/View/RequirementsTest.php | 14 +++++++------- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/_config/mimetypes.yml b/_config/mimetypes.yml index 48328042797..bd9ce94d759 100644 --- a/_config/mimetypes.yml +++ b/_config/mimetypes.yml @@ -362,7 +362,7 @@ SilverStripe\Control\HTTP: jpgm: video/jpm jpgv: video/jpeg jpm: video/jpm - js: application/javascript + js: text/javascript json: application/json jsonml: application/jsonml+json kar: audio/midi diff --git a/src/Control/HTTPResponse.php b/src/Control/HTTPResponse.php index 3cb4a498bbc..757fb91f2ab 100644 --- a/src/Control/HTTPResponse.php +++ b/src/Control/HTTPResponse.php @@ -363,7 +363,7 @@ protected function htmlRedirect() echo <<Redirecting to {$title}

- EOT diff --git a/src/Security/CMSSecurity.php b/src/Security/CMSSecurity.php index 290134d4397..73898012b88 100644 --- a/src/Security/CMSSecurity.php +++ b/src/Security/CMSSecurity.php @@ -133,7 +133,7 @@ protected function redirectToExternalLogin() $message - diff --git a/src/Security/MemberAuthenticator/CMSLoginHandler.php b/src/Security/MemberAuthenticator/CMSLoginHandler.php index a9049224faa..1610be45c28 100644 --- a/src/Security/MemberAuthenticator/CMSLoginHandler.php +++ b/src/Security/MemberAuthenticator/CMSLoginHandler.php @@ -90,7 +90,7 @@ protected function redirectToChangePassword() $message - diff --git a/src/View/Requirements_Backend.php b/src/View/Requirements_Backend.php index 869f636a289..53749ff8121 100644 --- a/src/View/Requirements_Backend.php +++ b/src/View/Requirements_Backend.php @@ -810,7 +810,7 @@ public function includeInHTML($content) foreach ($this->getJavascript() as $file => $attributes) { // Build html attributes $htmlAttributes = [ - 'type' => isset($attributes['type']) ? $attributes['type'] : "application/javascript", + 'type' => isset($attributes['type']) ? $attributes['type'] : null, 'src' => $this->pathForFile($file), ]; if (!empty($attributes['async'])) { @@ -832,7 +832,7 @@ public function includeInHTML($content) // Add all inline JavaScript *after* including external files they might rely on foreach ($this->getCustomScripts() as $key => $script) { // Build html attributes - $customHtmlAttributes = ['type' => 'application/javascript']; + $customHtmlAttributes = []; if (isset($this->customScriptAttributes[$key])) { foreach ($this->customScriptAttributes[$key] as $attrKey => $attrValue) { $customHtmlAttributes[$attrKey] = $attrValue; diff --git a/tests/php/Core/ConvertTest.php b/tests/php/Core/ConvertTest.php index fc497f6edb7..1cdbec6d17f 100644 --- a/tests/php/Core/ConvertTest.php +++ b/tests/php/Core/ConvertTest.php @@ -102,7 +102,7 @@ public function testHtml2raw() 'Strong tags with attributes are replaced with asterisks' ); - $val3 = ''; + $val3 = ''; $this->assertEquals( '', Convert::html2raw($val3), @@ -116,7 +116,7 @@ public function testHtml2raw() 'Style tags are completely removed' ); - $val5 = ""; + $val5 = ""; $this->assertEquals( '', Convert::html2raw($val5), diff --git a/tests/php/View/RequirementsTest.php b/tests/php/View/RequirementsTest.php index 7c900a1eb66..c01d547e402 100644 --- a/tests/php/View/RequirementsTest.php +++ b/tests/php/View/RequirementsTest.php @@ -395,7 +395,7 @@ public function testCustomType() $result ); $this->assertMatchesRegularExpression( - '#\n", $html ); @@ -1097,8 +1097,8 @@ public function testForceJsToBottom() $template = '
My header

Body

'; // The expected outputs - $expectedScripts = "\n" - . "\n" + . "\n"; $JsInHead = "$expectedScripts
My header

Body

"; @@ -1410,7 +1410,7 @@ public function testSriAttributes() /* Javascript has correct attributes */ $this->assertMatchesRegularExpression( - '##s", + "##s", $html, 'customScript is correctly not displaying original write' ); /* customScriptWithAttributes is overwritten by customScript */ $this->assertMatchesRegularExpression( - "##s", + "#//#s", $html, 'customScript is displaying latest write and clearing attributes' );