Attribute, single quote, double quote

Topics: Developer Forum, User Forum
Apr 2, 2008 at 1:46 PM
Hi,

I have been using this great framework in my HttpModule to parse / change HTML on the fly.
I find one issue when attribute value contains double quote for example onclick='javascript:alert("Hello World");'. The method HtmlNode.WriteAttribute should use single quote insted of double quote in that case.
I fix it in 3 places:
line 1364
if (att.XmlValue.IndexOf("\"") == -1)
outText.Write(" " + name + "=\"" + HtmlDocument.HtmlEncode(att.XmlValue) + "\"");
else
outText.Write(" " + name + "='" + HtmlDocument.HtmlEncode(att.XmlValue) + "'");
line 1397
if (att.Value.IndexOf("\"") == -1)
outText.Write(" " + name + "=\"" + att.Value + "\"");
else
outText.Write(" " + name + "='" + att.Value + "'");
and line 1407
if (att.Value.IndexOf("\"") == -1)
outText.Write(" " + name + "=\"" + att.Value + "\"");
else
outText.Write(" " + name + "='" + att.Value + "'");
I am not sure if it is the best fix, but it works fine for me. Is there better way to fix this issue?
Thanks,
Richard.
Jul 11, 2008 at 7:57 PM
Richard,
Thank you! This works great.  I was having some oddities with writing out Word HTML, (yes, I know Word HTML is horrible, but you need to support your clients) and this fixed the issues.

Thanks,
-Damien