Edgewall Software

Ticket #77 (closed defect: fixed)

Opened 8 years ago

Last modified 5 years 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 Download (0.7 KB) - added by cmlenz 8 years ago.
Possible fix… needs more testing

Change History

Changed 8 years 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 8 years ago by cmlenz

Possible fix… needs more testing

Changed 8 years 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 8 years 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 8 years 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


E-mail address and user name can be saved in the Preferences.


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