Smidge
Smidge copied to clipboard
Issue with Smidge HTML encoding single quote in onload function
Hi, I am creating a css bundle in my startup.cs file then calling it with the first method mentioned in the Rendering section. I am running into a bit of an issue due to the bit of code I'm trying to execute in onload.
When using smidge it renders the line with the ' HTML encoded to '

I cannot find any way to stop this from occurring when utilizing smidge. If I simply hotlink to a CSS file no encoding occurs. Please advise.
Can you please post examples of the code you are trying to use to render and what you are expecting as the output?
Hi, this is the line of code I am trying to render.
and it is rendering as shown in the screenshot in my first post with the HTML encoding on the single quotes.It should not HTML encode the single quotes as shown in the output here when bypassing smidge and just hotlinking the CSS file.

I can replicate this. The problem is the aspnet tag helper code TagBuilder.MergeAttributes automatically html encodes the values which cannot be prevented. There are a number of posts when you google TagBuilder + HtmlEncode. For example: https://social.msdn.microsoft.com/Forums/en-US/8d8a01fa-804c-4293-9c2b-488bba03ca4a/taghelper-needs-an-option-to-not-htmlencode-certain-attribute-values?forum=aspmvc
I'd prefer to not change the default behavior of how tag builders work and don't want to put in specific checks for attributes such as onload.
The article above mentions this is the correct approach anyways and the JS engine will parse the html encoded values correctly. I have tested this with onload="window.alert('hello')" which renders as <link href="/sb/test-bundle-4.css.v637865264169070063" onload="window.alert('hello')" rel="stylesheet" /> and the JS executes and I still get an alert so I believe this is the standard/expected behavior.