aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-07-23 01:28:51 +0200
committerGitHub <noreply@github.com>2023-07-23 01:28:51 +0200
commit97b994941f4f61a26c608627ed9d23d02ef6ebb1 (patch)
tree63c4f6489e2563a98f59fdbb818e6a155048f0c9
parent446b2d283fdb8f2d84b052d5be7901db00b7bde8 (diff)
parentad2727aef847ef8a6f276386294f8a248671d80a (diff)
downloadnextcloud-server-97b994941f4f61a26c608627ed9d23d02ef6ebb1.tar.gz
nextcloud-server-97b994941f4f61a26c608627ed9d23d02ef6ebb1.zip
Merge pull request #39462 from nextcloud/backport/39456/stable27
[stable27] fix: Correctly add `module` content type to script tags with versions
-rw-r--r--lib/private/legacy/template/functions.php3
-rw-r--r--tests/lib/TemplateFunctionsTest.php12
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php
index 7081bd4f743..0d386625ab3 100644
--- a/lib/private/legacy/template/functions.php
+++ b/lib/private/legacy/template/functions.php
@@ -101,7 +101,8 @@ function emit_script_tag(string $src, string $script_content = '', string $conte
*/
function emit_script_loading_tags($obj) {
foreach ($obj['jsfiles'] as $jsfile) {
- $type = str_ends_with($jsfile, '.mjs') ? 'module' : '';
+ $fileName = explode('?', $jsfile, 2)[0];
+ $type = str_ends_with($fileName, '.mjs') ? 'module' : '';
emit_script_tag($jsfile, '', $type);
}
if (!empty($obj['inline_ocjs'])) {
diff --git a/tests/lib/TemplateFunctionsTest.php b/tests/lib/TemplateFunctionsTest.php
index b2b25ab654c..aa9ba32610d 100644
--- a/tests/lib/TemplateFunctionsTest.php
+++ b/tests/lib/TemplateFunctionsTest.php
@@ -86,6 +86,18 @@ class TemplateFunctionsTest extends \Test\TestCase {
]);
}
+ public function testEmitScriptLoadingTagsWithVersion() {
+ // Test mjs js and inline content
+ $pattern = '/src="some\.mjs\?v=ab123cd"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module
+ $pattern .= '<script[^>]+src="other\.js\?v=12abc34"[^>]*>.+\n'; // other.js as plain javascript
+ $pattern .= '/'; // no flags
+
+ $this->expectOutputRegex($pattern);
+ emit_script_loading_tags([
+ 'jsfiles' => ['some.mjs?v=ab123cd', 'other.js?v=12abc34'],
+ ]);
+ }
+
// ---------------------------------------------------------------------------
// Test relative_modified_date with dates only
// ---------------------------------------------------------------------------