[Mono-bugs] [Bug 402442] New: Any Xml. Linq new XNode call with parameters will fail on the first text parameter

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Jun 20 21:23:58 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=402442


           Summary: Any Xml.Linq new XNode call with parameters will fail on
                    the first text parameter
           Product: Mono: Class Libraries
           Version: 1.9.0
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: Novell-Bugzilla at bobf.frankston.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Other


If you do new Xelement("Foo", "Bar") it will fail because ShrinkArray tries to
append each string to a null pointer. The work around is
           new Xelement("Foo") {Value="Bar"}
but that's not obvious and doesn't address the more general cases

The fix is simple -- test prev for null and assign rather than append as in
  prev = prev == null ? o : prev + o

public static IEnumerable<object> ShrinkArray (params object [] content) {
    if (content == null || content.Length == 0)
        yield break;
    string prev = null;
    foreach (object o in content) {
        if (o is XNode) {
            if (prev != null) {
                yield return prev;
                prev = null;
            }
            yield return o;
        } else {
            prev += o;
        }
    }
    if (prev != null)
        yield return prev;
}


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list