-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special-case parsing of <script> and <style> elements, similarly to HTML
In HTML, the content of <script> and <style> tags should not be parsed as HTML, the parser should simply look for the end tag. This eliminates the need to HTML-encode all `<` operators (or even HTML inlined in string literals). To align dothtml and HTML, the patch implements this behavior in dothtml. The change may easily break someone's code, if they already have a script element with entities like <, so it is possible to configure which tags will be parsed as "raw text". By default, it is script, style and also dot:InlineScript and dot:HtmlLiteral (as suggested in #1428). This setting is up for debate. resolves #1445
- Loading branch information
Showing
6 changed files
with
319 additions
and
14 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Framework/Framework/Compilation/Parser/Dothtml/DotvvmSyntaxConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DotVVM.Framework.Configuration; | ||
|
||
namespace DotVVM.Framework.Compilation.Parser.Dothtml; | ||
|
||
public sealed class DotvvmSyntaxConfiguration | ||
{ | ||
private readonly HashSet<string> rawTextElements; | ||
public IEnumerable<string> RawTextElements => rawTextElements; | ||
|
||
public bool IsRawTextElement(string elementName) => | ||
rawTextElements.Contains(elementName); | ||
|
||
public DotvvmSyntaxConfiguration(IEnumerable<string> rawTextElements) | ||
{ | ||
this.rawTextElements = rawTextElements.ToHashSet(StringComparer.OrdinalIgnoreCase); | ||
} | ||
|
||
public static DotvvmSyntaxConfiguration FromMarkupConfig(DotvvmMarkupConfiguration markupConfiguration) | ||
{ | ||
var rawTextElements = markupConfiguration.RawTextElements; | ||
|
||
return new DotvvmSyntaxConfiguration(rawTextElements); | ||
} | ||
|
||
public static DotvvmSyntaxConfiguration Default { get; } = new DotvvmSyntaxConfiguration(["script", "style", "dot:InlineScript", "dot:HtmlLiteral"]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.