Merge pull request #4435 from sbwalker/dev

allow <style> tags to be injected using HeadContent
This commit is contained in:
Shaun Walker 2024-07-18 15:01:43 -04:00 committed by GitHub
commit 8ac1217165
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,21 +66,17 @@
{ {
if (!string.IsNullOrEmpty(content)) if (!string.IsNullOrEmpty(content))
{ {
// format head content, remove scripts, and filter duplicate elements if (PageState.RenderMode == RenderModes.Interactive)
content = content.Replace("\n", "");
var index = content.IndexOf("<");
while (index >= 0)
{ {
var element = content.Substring(index, content.IndexOf(">", index) - index + 1); // remove scripts
if (!string.IsNullOrEmpty(element) && (PageState.RenderMode == RenderModes.Static || (!element.ToLower().StartsWith("<script") && !element.ToLower().StartsWith("</script")))) var index = content.IndexOf("<script");
while (index >= 0)
{ {
if (!headcontent.Contains(element)) content = content.Remove(index, content.IndexOf("</script>") + 9 - index);
{ index = content.IndexOf("<script");
headcontent += element + "\n";
}
} }
index = content.IndexOf("<", index + 1);
} }
headcontent += content + "\n";
} }
return headcontent; return headcontent;
} }