5
Vote

Self-closing slash dissappears for img nodes

description

When setting innerHtml for a node the closing slash of an img tag dissappears. Noticed in C#, here is code to reproduce:
 
Debug.WriteLine(HtmlNode.CreateNode("<img id=\"a\" />").OuterHtml);
 
Expected output: "<img id="a" />" or <img id="a"></img>"
 
Actual output: "<img id="a">"
 
Using a HtmlDocument with OptionOutputAsXml:
 
HtmlDocument doc = new HtmlDocument();
doc.OptionOutputAsXml = true;
HtmlNode node = doc.CreateElement("x");
node.InnerHtml = "<img id=\"bla\" />";
doc.DocumentNode.AppendChild(node);
Debug.WriteLine(doc.DocumentNode.OuterHtml);
 
Expected output: "<x><img id="bla" /></x>" or "<x><img id="bla"></img></x>".
 
Actual output: "<x><img id="bla"></x>".
 
If I replace "img" with "MyImageTag" output is as expected: "<myimagetag id="bla"></myimagetag>".

comments

Nenotlep wrote Jul 26, 2012 at 9:19 AM

The CodePlex issue tracker is not very good, is it?

Nenotlep wrote Jul 26, 2012 at 9:21 AM

This is also reproducible using input HTML like "<img id="bla"></img>".
Output for that is yet again "<img id="bla">".

MaxPRafferty wrote Aug 23, 2012 at 3:56 PM

Apparently not. This issue is also reproducible using <input> tags.