Edgewall Software

Ticket #77 (closed defect: fixed)

Opened 20 months ago

Last modified 20 months ago

Match templates can match their own output

Reported by: dackze+genshi@… Owned by: cmlenz
Priority: major Milestone: 0.3.5
Component: Template processing Version: devel
Keywords: Cc:

Description

This is really hurting my head and I'm not exactly sure how to explain this, so here are some examples:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
  <body py:match="body" py:content="select('*')" />
  <h1 py:match="h1">
    ${select('text()')}
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>

Produces:

<html xmlns="http://www.w3.org/1999/xhtml">
  <body><h1>
    Hello!
    Goodbye!
    Goodbye!
  </h1></body>
</html>

It seems to be triggered by the first match template outputting what the second match template matches, and by the name of the second match template matching its own query. If you make the first match template not output the <h1>Hello</h1> element, or change the <h1 py:match="h1"> element to not match its own query, the problem disappears.

I'm not sure if this is intentional, but for what it's worth, Kid doesn't seem to behave this way:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://purl.org/kid/ns#">
  <body py:match="item.tag == '{http://www.w3.org/1999/xhtml}body'"
        py:content="[item.text] + item[:]" />
  <h1 py:match="item.tag == '{http://www.w3.org/1999/xhtml}h1'">
    ${item.text}
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>

Produces:

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">



  <body>
    <h1>
    Hello!
    Goodbye!
  </h1>
  </body>

The examples are contrived, but I originally ran into this with a form template that filled in fields via match templates. I had a match template that put error messages beneath fields with invalid input, and when I threw a match-based layout template into the mix, I started getting two of each error list.

Also, this seems to happen in all of the current branches, the current trunk, and all of the 0.3 tags.

Attachments

match_fix.diff (0.7 kB) - added by cmlenz 20 months ago.
Possible fix… needs more testing

Change History

Changed 20 months ago by dackze+genshi@…

Here's another weird side effect of this behavior:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
  <body py:match="body" py:content="select('*')" />
  <h1 py:match="h1">
    <text>
      ${select('text()')}
    </text>
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>

Produces:

<html xmlns="http://www.w3.org/1999/xhtml">
  <body><h1>
    <text>
    Goodbye!
    </text>
    Goodbye!
  </h1></body>
</html>

The "Hello!" wasn't selected. If you remove the first match template, it is selected:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
  <h1 py:match="h1">
    <text>
      ${select('text()')}
    </text>
    Goodbye!
  </h1>

  <body>
    <h1>Hello!</h1>
  </body>
</html>

Produces:

<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <h1>
    <text>
      Hello!
    </text>
    Goodbye!
  </h1>
  </body>
</html>

Changed 20 months ago by cmlenz

Possible fix… needs more testing

Changed 20 months ago by cmlenz

  • status changed from new to closed
  • resolution set to fixed

Fix checked in in [444].

Thanks a lot for those test cases, very helpful!

Changed 20 months ago by cmlenz

  • status changed from closed to reopened
  • resolution fixed deleted
  • milestone changed from 0.4 to 0.3.5

Should be ported 0.3.x.

Changed 20 months ago by cmlenz

  • status changed from reopened to closed
  • resolution set to fixed

Ported to 0.3.x in [449].

Add/Change #77 (Match templates can match their own output)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.