Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitizer process attributes with no values #93

Closed
Baidaly opened this issue Nov 10, 2016 · 2 comments
Closed

Sanitizer process attributes with no values #93

Baidaly opened this issue Nov 10, 2016 · 2 comments

Comments

@Baidaly
Copy link

Baidaly commented Nov 10, 2016

I use special ExtJS HTML templates that need to have attributes without value. E.g.

<tpl if="true">
    TEST
<tpl else>
    TEST 2
</tpl>

When I run Sanitizer, it converts it to

<tpl if="true">
    TEST
<tpl else="">
    TEST 2
</tpl>

Which is not valid for ExtJS. Is there a way to leave attributes as is?

Thank you!

@tiesont
Copy link

tiesont commented Nov 11, 2016

I think that's actually due to AngleSharp (see AngleSharp #434), and it's likely because the latter is correct XML. From reading that issue, it seems like this is intentional, at least for now.

It's a kludge, but you can probably post-process the sanitized markup to remove the empty attribute value:

markup = markup.Replace("=\"\"", string.Empty);

Not pretty, but I don't see why it wouldn't work.

@mganss
Copy link
Owner

mganss commented Nov 11, 2016

Browsers seem to behave the same way:

var d = document.createElement("div");
d.innerHTML = '<span title>Test</span>';
d.innerHTML  <span title="">Test</span>

The sanitizer used on GitHub does the opposite: <b title="">Test</b> becomes <b title>Test</b>: Test

Besides what @tiesont suggested, you can also provide your own instance of IMarkupFormatter to the OutputFormatter property by copying the HtmlFormatter class (I'll make the methods virtual in the next release) and changing the Attribute method. Adding the following line before this line should do the trick:

if (string.IsNullOrEmpty(value)) return temp.ToString();

@mganss mganss closed this as completed Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants