Edgewall Software

Opened 15 years ago

Last modified 8 years ago

#360 new defect

py:attrs can create duplicate attributes

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

Description

Given the following script genshi_test.py:

import genshi
import genshi.template

print genshi.template.MarkupTemplate("""
<root
   xmlns:py="http://genshi.edgewall.org/"
   xmlns:xlink="http://www.w3.org/1999/xlink">
  <image xlink:href="default_img.png" py:attrs="{'xlink:href':'non_default_img.png'}"/>
</root>
""").generate().render()

the following (invalid) XML is generated:

<root xmlns:xlink="http://www.w3.org/1999/xlink">
  <image xlink:href="default_img.png" xlink:href="non_default_img.png"/>
</root>

xmllint reports a parse error as follows:

cduffy@shiny-ubuntu:~$ xmllint genshi_test.out.xml 
genshi_test.out.xml:2: parser error : Attribute xlink:href redefined
  <image xlink:href="default_img.png" xlink:href="non_default_img.png"/>
                                                                      ^

Given that the documentation indicates that py:attrs is able to modify existing attributes, my expectation as a user is that the preexisting attribute will be deleted.

Change History (5)

comment:1 Changed 15 years ago by cmlenz

  • Milestone changed from 0.6 to 0.7

comment:2 follow-up: Changed 15 years ago by Carsten Klein <carsten.klein@…>

Coalescing of multiple same name attributes is actually already part of the Attrs object.

The problem here, so it seems, is the use of namespace aliased attributes.

A similar test

        <div xmlns:xlink="xlink-schema-ref" xlink:href="default_img.png" py:attrs="{'xlink:href':'non_default_img.png'}">test</div>

would yield

        <div xmlns:ns1="xlink-schema-ref" ns1:href="default_img.png" xlink:href="non_default_img.png">test</div>

The latter, however seems to be a different issue with genshi and namespaces..., so it might be just irrelevant here.

comment:3 in reply to: ↑ 2 Changed 15 years ago by Carsten Klein <carsten.klein@…>

Replying to Carsten Klein <carsten.klein@…>:

And here for the positive:

        <div class="foo" py:attrs="{'class':'bar', 'class':'foobar'}">test</div>
        <div py:attrs="{'class':'bar', 'class':'foobar'}" class="foo">test</div>

and the expected result is

        <div class="foobar">test</div>
        <div class="foobar">test</div>

I can see that in the current test cases the duplicate attribute is missing, perhaps that should be added.

Also an integration test using a combination of the OP's test case and non namespace aliased attributes should also be integrated.

comment:4 Changed 14 years ago by Carsten Klein <carsten.klein@…>

Note: fixing this is rather complicated, as it will require changes to the markup template's extract directives method and also the way that the Attrs directive is currently implemented.

I.e. the extract directives method will extract the Attrs directive but will not allow it to modify /extend upon the available attributes already defined on the element on which it was declared.

comment:5 Changed 8 years ago by hodgestar

  • Milestone changed from 0.7 to 0.9

Moved to milestone 0.9.

Note: See TracTickets for help on using tickets.