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

HtmlMarkupFormatter doesn't write all attributes properly #348

Closed
jcarrenog opened this issue May 24, 2016 · 2 comments
Closed

HtmlMarkupFormatter doesn't write all attributes properly #348

jcarrenog opened this issue May 24, 2016 · 2 comments
Labels

Comments

@jcarrenog
Copy link

When I want to serialize an element, the underlying HtmlMarkupFormatter transforms any "&" characters contained in attributes into "&"

Example:

    var btn = document.CreateElement("a");
    btn.InnerHtml = "Test";
    btn.SetAttribute("href", "http://google.com?param=param&q=test");
    var html = btn.OuterHtml; // <-- http://google.com?param=param&amp;q=test

Digging into the code, I've found this in HtmlMarkupFormatter.cs, line 118

String IMarkupFormatter.Attribute(IAttr attribute)
...
    for (var i = 0; i < value.Length; i++)
    {
        switch (value[i])
        {
            case Symbols.Ampersand: temp.Append("&amp;"); break;
            case Symbols.NoBreakSpace: temp.Append("&nbsp;"); break;
            case Symbols.DoubleQuote: temp.Append("&quot;"); break;
            default: temp.Append(value[i]); break;
        }
    }

I think that, apart from the double quote, the rest of symbols are all valid into an attribute value.

@FlorianRappl
Copy link
Contributor

This is by specification, see the string escaping that needs to be applied on attribute values..

@jcarrenog
Copy link
Author

You are right. I haven't noticed that any browser behaves this way.

Thank you for your response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants