Edgewall Software

Ticket #243: ticket243.diff

File ticket243.diff, 2.7 KB (added by cmlenz, 4 years ago)

Patch that should address the issue, but not tested much

  • genshi/template/markup.py

     
    278278                    if 'not_buffered' not in hints: 
    279279                        content = list(content) 
    280280 
    281                     if tail: 
    282                         for test in [mt[0] for mt in match_templates]: 
    283                             test(tail[0], namespaces, ctxt, updateonly=True) 
    284  
    285281                    # Make the select() function available in the body of the 
    286282                    # match template 
     283                    selected = [False] 
    287284                    def select(path): 
     285                        selected[0] = True 
    288286                        return Stream(content).select(path, namespaces, ctxt) 
    289287                    vars = dict(select=select) 
    290288 
     
    300298                            ctxt, start=idx + 1, **vars): 
    301299                        yield event 
    302300 
     301                    # If the match template did not actually call select to 
     302                    # consume the matched stream, the original events need to 
     303                    # be consumed here or they'll get appended to the output 
     304                    if not selected[0]: 
     305                        for event in content: 
     306                            pass 
     307 
     308                    # Let the remaining match templates know about the event so 
     309                    # they get a chance to update their internal state 
     310                    for test in [mt[0] for mt in match_templates]: 
     311                        test(tail[0], namespaces, ctxt, updateonly=True) 
     312 
    303313                    break 
    304314 
    305315            else: # no matches 
  • genshi/template/tests/markup.py

     
    708708            </body> 
    709709        </html>""", tmpl.generate().render()) 
    710710 
     711    def test_match_without_select(self): 
     712        # See <http://genshi.edgewall.org/ticket/243> 
     713        xml = ("""<html xmlns:py="http://genshi.edgewall.org/"> 
     714          <py:match path="body" buffer="false"> 
     715            <body> 
     716              This replaces the other text. 
     717            </body> 
     718          </py:match> 
     719          <body> 
     720            This gets replaced. 
     721          </body> 
     722        </html>""") 
     723        tmpl = MarkupTemplate(xml, filename='test.html') 
     724        self.assertEqual("""<html> 
     725            <body> 
     726              This replaces the other text. 
     727            </body> 
     728        </html>""", tmpl.generate().render()) 
    711729 
     730 
    712731def suite(): 
    713732    suite = unittest.TestSuite() 
    714733    suite.addTest(doctest.DocTestSuite(MarkupTemplate.__module__))