mirror of
https://github.com/nextcloud/server.git
synced 2026-05-19 16:39:59 -04:00
fix: Correctly add module content type to script tags when scripts with versions are used
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
446b2d283f
commit
ad2727aef8
2 changed files with 14 additions and 1 deletions
|
|
@ -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'])) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue