Skip to content

HtmlMarkupFormatter doesn't write all attributes properly #348

@jcarrenog

Description

@jcarrenog

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions