[Mono-bugs] [Bug 48337][Min] New - XmlTextReader allows dup attribute if defined in duplicate namespaces.

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 9 Sep 2003 21:11:46 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by bmaurer@users.sf.net.

http://bugzilla.ximian.com/show_bug.cgi?id=48337

--- shadow/48337	2003-09-09 21:11:46.000000000 -0400
+++ shadow/48337.tmp.24818	2003-09-09 21:11:46.000000000 -0400
@@ -0,0 +1,79 @@
+Bug#: 48337
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: System.XML
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: bmaurer@users.sf.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: XmlTextReader allows dup attribute if defined in duplicate namespaces.
+
+Description of Problem:
+The following document, though invalid, is parsed by mono:
+			<myElement xmlns:mono='http://go-mono.com'
+xmlns:go-mono='http://go-mono.com'>
+				<verse mono:part='mary had a little' go-mono:part='lamb' />
+			</myElement>
+
+Although the strings "go-mono:part" and "mono:part" are different, due to
+the way the namespaces are defined, the document is invalid, as stated by
+xmllint:
+
+a.xml:2: error: Attribute part in http://go-mono.com redefined
+                                <verse mono:part='mary had a little'
+go-mono:part='lamb' />
+
+
+Steps to reproduce the problem:
+using System;
+using System.IO;
+using System.Xml;
+
+class T {
+	static void Main ()
+	{
+		XmlReader r = new XmlTextReader (new StringReader (@"
+			<myElement xmlns:mono='http://go-mono.com'
+xmlns:go-mono='http://go-mono.com'>
+				<verse mono:part='mary had a little' go-mono:part='lamb' />
+			</myElement>
+		"));
+		new XmlTextWriter (Console.Out).WriteNode (r, true);
+	}
+}
+Actual Results:
+[benm@Ben attrbug]$ mono a.exe
+ 
+                        <myElement xmlns:mono="http://go-mono.com"
+xmlns:go-mono="http://go-mono.com">
+                                <verse mono:part="mary had a little"
+go-mono:part="lamb" />
+                        </myElement>
+
+
+Expected Results:
+An exception should be thrown.
+
+How often does this happen? 
+Always
+
+Additional Information:
+The root of this problem is that when the XmlTextReader reads attributes
+they are stored in a Hashtable by their name (ie, the prefix and localname).
+
+We could replace this with QNames, however, this would hurt performance, as
+it would cause object allocation. I recommend that we replace the current
+Hashtable/ArrayList combo with an array of a new class AttrInfo. It should
+hold the parsed name and value. We can do a search through the list for
+duplicate attributes (since the number of attributes on an element is
+usually few, the speed benefit from the Hashtable is outweighted by the
+cost of hashing). Since all the names will be taken from the NameTable, we
+can use Object.ReferenceEquals, and avoid the cost of a string compare.