Edgewall Software

Opened 17 years ago

Last modified 8 years ago

#160 new defect

Genshi builder incorrectly leaks namespace scope to children

Reported by: ben@… Owned by: cmlenz
Priority: major Milestone: 0.9
Component: General Version: devel
Keywords: Cc:

Description

from genshi.core import Namespace
from genshi.builder import Element
ns1 = Namespace("http://ns1")
ns2 = Namespace("http://ns2")

print str(Element(ns1.a)(Element(ns2.a)(), Element(ns2.b)(), Element(ns2.c)()))

Output:

<a xmlns="http://ns1"><a xmlns="http://ns2"/><b/><c/></a>

According to my understanding of the spec, specifically the scoping and defaulting rules, this output is equivalent to

<a xmlns="http://ns1"><a xmlns="http://ns2"/><b xmlns="http://ns1"/><c xmlns="http://ns1"/></a>

but the code should produce output equivalent to

<a xmlns="http://ns1"><a xmlns="http://ns2"/><b xmlns="http://ns2"/><c xmlns="http://ns2"/></a>

Attachments (2)

NamespaceFlattener.py (6.7 KB) - added by ben@… 17 years ago.
NamespaceFlattenerTest.py (1.2 KB) - added by ben@… 17 years ago.

Download all attachments as: .zip

Change History (8)

Changed 17 years ago by ben@…

Changed 17 years ago by ben@…

comment:1 Changed 17 years ago by ben@…

I have rewritten NamespaceFlattener to fix this bug (and, I believe, some other edge cases). I am also including some unit tests for my code. Hope this helps!

comment:2 Changed 17 years ago by athomas

Can you attach a patch of your changes to the filter and tests?

You can generate one from the SVN checkout with svn diff.

comment:3 Changed 17 years ago by cmlenz

  • Milestone changed from 0.5 to 0.6

A patch would be great. Otherwise this will have to wait for the next release.

comment:4 Changed 15 years ago by cmlenz

  • Milestone changed from 0.6 to 0.6.1

comment:5 Changed 15 years ago by anonymous

Hm, I think that genshi operates correctly.

In your example, a declares the default xml namespace to be ns2. Whereas b and c are direct children of the enclosing anchor a, which declares ns1 as the default namespace, which is naturally inherited by both b and c.

See also http://csharpcomputing.com/XMLTutorial/Lesson5.htm for more information on default namespace inheritance.

To sum it up, children of an element will inherit the default namespace of that element, unless a descendant declares a different default namespace. In that case, any children of the descendant will inherit the descendant's default namespace.

comment:6 Changed 8 years ago by hodgestar

  • Milestone changed from 0.6.1 to 0.9

Move to milestone 0.9.

Note: See TracTickets for help on using tickets.