HtmlString
for handling of both HTML and plain text strings
#5982
Labels
HtmlString
for handling of both HTML and plain text strings
#5982
One repeating issue with the handling of strings passed to a function is that it is not always clear if the content has been encoded already and is safe for output. When in doubt we encode the string which can cause intended HTML to be encoded or already encoded strings to be encoded twice.
There is also the inverse case where an API previously only expected regular strings but now should also allow safe HTML to be used. This often leads to separate API methods or additional parameters, which is both cumbersome and error-prone.
This moves the responsibility of properly encoding the value to the callee. The two distinct methods
fromText()
andfromSafeHtml()
provide the necessary guardrails to prevent accidental misuse.The text was updated successfully, but these errors were encountered: