Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Special characters are not decoded/encoded #2

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Serialize a value with special characters like "<", "&", """, ...

What is the expected output? What do you see instead?
For "&" I expect "&amp;" etc
Instead of an xml error when loading the string in a xml document

What version of the product are you using? On what operating system?
r115, XP, .NET 4

Please provide any additional information below.
To Fix reading, just rewrite NullFieldDefinition.cs
public object Convert(object value)
{
    return value;
}
to
public object Convert(object value)
{
    if (value.GetType() == typeof(string))
    {
        value = HttpUtility.HtmlDecode(value.ToString());
    }

    return value;
}

In my opinion value should always be a string object. But I didn't wrote
the framework... maybe the if is not needed

To Fix writing, just rewrite NXmlNodeWriter.cs
public void AddAttribute(string attributeName, string value)
{
    if (streamWriter != null)
    {
        streamWriter.Write(string.Format(" {0}=\"{1}\"", attributeName,
value));
    }
}
to
public void AddAttribute(string attributeName, string value)
{
    if (streamWriter != null)
    {
        value = HttpUtility.HtmlEncode(value);
        streamWriter.Write(string.Format(" {0}=\"{1}\"", attributeName,
value));
    }
}

Original issue reported on code.google.com by kue...@gmail.com on 12 Mar 2010 at 3:10

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions