I am likely missing something painfully obvious, so grab your popcorn and get ready for a laugh.
I am currently struggling with handling HTML entities, specifically, getting Angular to render them correctly. I am aware of the existence of the DOMSanitizer and how to use it, but I don't think it's the correct solution for my situation.
Users are able to submit forms that contain <textarea> inputs. Users should be able to submit text that contains HTML entities. After submitting, our PHP server encodes this text using htmlspecialchars and stores the result in our DB. If a user wants to write \<script type="javascript">alert('hello');\</script>, then there must be a way for that to be rendered. Also, as far as I can tell, this code snippet is also exactly why I can use the DOMSanitizer's byPassSecurity functions...right?
The Problem
The user now goes back to the previous form to edit their text. Currently my Angular app displays the encoded HTML entities (e.g. "<" instead of "<"). I am using ReactiveForms.
The Question
What is the best practice for rendering the symbol for an HTML entity within a FormControl? I have found plenty of solutions that implement custom pipes which make use of RegExp replacements and the sort, but surely there is a mechanism baked into either the browser or Angular?
Thank you in advance.
source https://stackoverflow.com/questions/76230495/angular-textarea-formcontrol-html-entities
No comments:
Post a Comment