Edgewall Software

Ticket #232 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

append transformation doesn't work at the end of stream

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

Description

trying to insert past the end of stream results in an extra final tag:

>>> foo = '<em>foo</em>'
>>> print HTML(foo) | Transformer('//em').after('bar')
<em>foo</em>bar</em>

The following patch fixes:

Index: transform.py
===================================================================
--- transform.py	(revision 852)
+++ transform.py	(working copy)
@@ -980,6 +980,7 @@
 
         :param stream: The marked event stream to filter
         """
+        stopped = False
         for mark, event in stream:
             yield mark, event
             if mark:
@@ -987,13 +988,15 @@
                     try:
                         mark, event = stream.next()
                     except StopIteration:
+                        stopped = True
                         break
                     if not mark:
                         break
                     yield mark, event
                 for subevent in self._inject():
                     yield subevent
-                yield mark, event
+                if not stopped:
+                    yield mark, event
 
 
 class PrependTransformation(InjectorTransformation):

admittedly this is a niche case but I see no reason not to do this (and am also not sure if other transforms need patching as well)

Attachments

Change History

Changed 6 years ago by cmlenz

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

Alec fixed this in [868].

Add/Change #232 (append transformation doesn't work at the end of stream)

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.