summaryrefslogtreecommitdiffstats
path: root/lib/private/legacy
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-03-22 09:17:28 +0100
committerGitHub <noreply@github.com>2023-03-22 09:17:28 +0100
commit8b4d49cf506d202c4b7ab58f453cdc84a30bca38 (patch)
treecfaaa6ee6ea356014349417788f0125dae3a4304 /lib/private/legacy
parent9c7d7139b6d7487275c5ad18645a0770c23761d9 (diff)
parentd461da3b04dfb2d6b7e6bad8ebf9b592d3008f20 (diff)
downloadnextcloud-server-8b4d49cf506d202c4b7ab58f453cdc84a30bca38.tar.gz
nextcloud-server-8b4d49cf506d202c4b7ab58f453cdc84a30bca38.zip
Merge pull request #36057 from nextcloud/feat/esm-js-scripts
Diffstat (limited to 'lib/private/legacy')
-rw-r--r--lib/private/legacy/template/functions.php16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/private/legacy/template/functions.php b/lib/private/legacy/template/functions.php
index 56c488d5abe..7081bd4f743 100644
--- a/lib/private/legacy/template/functions.php
+++ b/lib/private/legacy/template/functions.php
@@ -72,14 +72,19 @@ function emit_css_loading_tags($obj) {
* Prints a <script> tag with nonce and defer depending on config
* @param string $src the source URL, ignored when empty
* @param string $script_content the inline script content, ignored when empty
+ * @param string $content_type the type of the source (e.g. 'module')
*/
-function emit_script_tag($src, $script_content = '') {
+function emit_script_tag(string $src, string $script_content = '', string $content_type = '') {
+ $nonceManager = \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class);
+
$defer_str = ' defer';
- $s = '<script nonce="' . \OC::$server->getContentSecurityPolicyNonceManager()->getNonce() . '"';
+ $type = $content_type !== '' ? ' type="' . $content_type . '"' : '';
+
+ $s = '<script nonce="' . $nonceManager->getNonce() . '"';
if (!empty($src)) {
// emit script tag for deferred loading from $src
- $s .= $defer_str.' src="' . $src .'">';
- } elseif (!empty($script_content)) {
+ $s .= $defer_str.' src="' . $src .'"' . $type . '>';
+ } elseif ($script_content !== '') {
// emit script tag for inline script from $script_content without defer (see MDN)
$s .= ">\n".$script_content."\n";
} else {
@@ -96,7 +101,8 @@ function emit_script_tag($src, $script_content = '') {
*/
function emit_script_loading_tags($obj) {
foreach ($obj['jsfiles'] as $jsfile) {
- emit_script_tag($jsfile, '');
+ $type = str_ends_with($jsfile, '.mjs') ? 'module' : '';
+ emit_script_tag($jsfile, '', $type);
}
if (!empty($obj['inline_ocjs'])) {
emit_script_tag('', $obj['inline_ocjs']);