From 9c89852e97a667b5ee87af054b7000e9a52fd9d1 Mon Sep 17 00:00:00 2001 From: JoshiCodes <55353244+JoshiCodes@users.noreply.github.com> Date: Fri, 13 Nov 2026 22:34:31 +0100 Subject: [PATCH] fix: register the index.html transformation under the shared pattern File Transformation only runs the callbacks whose pattern string equals the requested path, so the anchored pattern was skipped whenever another plugin had registered the plain one. Script chunks that match the pattern as a regex are returned unchanged. --- .../IndexHtmlTransformerTests.cs | 19 +++++++++++++++++++ .../Injection/FileTransformationRegistrar.cs | 8 +++++--- .../Injection/IndexHtmlTransformer.cs | 8 +++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Plugin.Herald.Tests/IndexHtmlTransformerTests.cs b/Jellyfin.Plugin.Herald.Tests/IndexHtmlTransformerTests.cs index abe735b..083d268 100644 --- a/Jellyfin.Plugin.Herald.Tests/IndexHtmlTransformerTests.cs +++ b/Jellyfin.Plugin.Herald.Tests/IndexHtmlTransformerTests.cs @@ -31,6 +31,25 @@ public class IndexHtmlTransformerTests Assert.Equal(Script, IndexHtmlTransformer.Inject(Script)); } + [Fact] + public void Inject_LeavesScriptsThatMentionABodyTagAlone() + { + const string Script = "(self.webpackChunk=self.webpackChunk||[]).push([[17244],{t:\"
\"}]);"; + + Assert.Equal(Script, IndexHtmlTransformer.Inject(Script)); + } + + [Fact] + public void Inject_KeepsTagsOtherPluginsAdded() + { + const string Other = ""; + var page = Page.Replace("", Other + "", StringComparison.Ordinal); + + var result = IndexHtmlTransformer.Inject(page); + + Assert.Contains(Other + IndexHtmlTransformer.ScriptTag + "", result, StringComparison.Ordinal); + } + [Fact] public void Transform_HandlesAnEmptyPayload() { diff --git a/Jellyfin.Plugin.Herald/Injection/FileTransformationRegistrar.cs b/Jellyfin.Plugin.Herald/Injection/FileTransformationRegistrar.cs index ba0d1d3..20970d0 100644 --- a/Jellyfin.Plugin.Herald/Injection/FileTransformationRegistrar.cs +++ b/Jellyfin.Plugin.Herald/Injection/FileTransformationRegistrar.cs @@ -17,9 +17,11 @@ namespace Jellyfin.Plugin.Herald.Injection; public class FileTransformationRegistrar : IHostedService { private const string InterfaceTypeName = "Jellyfin.Plugin.FileTransformation.PluginInterface"; - // File Transformation treats this as a regular expression. Unanchored, "index.html" would also - // match script chunks such as "session-login-index-html..chunk.js". - private const string IndexHtmlPattern = @"^index\.html$"; + // Has to be the literal "index.html" every other plugin registers. File Transformation groups + // callbacks by pattern string and, for a request, only runs the group whose key equals the path; + // a differently spelled pattern is skipped as soon as another plugin uses the plain one. + // The pattern is also used as a regex and matches some script chunks, which the transformer ignores. + private const string IndexHtmlPattern = "index.html"; private static readonly Guid _transformationId = Guid.Parse("bf6fabc9-721c-46d9-9e13-3cc415a9ae1b"); private readonly ILogger _logger; diff --git a/Jellyfin.Plugin.Herald/Injection/IndexHtmlTransformer.cs b/Jellyfin.Plugin.Herald/Injection/IndexHtmlTransformer.cs index a4558d7..93d1f8d 100644 --- a/Jellyfin.Plugin.Herald/Injection/IndexHtmlTransformer.cs +++ b/Jellyfin.Plugin.Herald/Injection/IndexHtmlTransformer.cs @@ -37,7 +37,7 @@ public static class IndexHtmlTransformer } /// - /// Inserts the script tag before the closing body tag. Content without one is not a page and is left alone. + /// Inserts the script tag before the closing body tag. Anything that is not an HTML page is left alone. /// /// The page. /// The page with the script tag. @@ -50,6 +50,12 @@ public static class IndexHtmlTransformer return html; } + // File Transformation also hands over script chunks whose name happens to match the pattern. + if (!html.Contains("", StringComparison.OrdinalIgnoreCase); return index < 0 ? html : html.Insert(index, ScriptTag); }