Edgewall Software

Ticket #429: t429-fix.patch

File t429-fix.patch, 2.5 KB (added by cboos, 12 years ago)

... then fix this issue (applies on t429-refactor-r1038.patch)

  • genshi/output.py

    # HG changeset patch
    # Parent 69c74a6a19b4786c939b14aa4af8ef314e567659
    #429: don't cache `(TEXT, Markup)` in serializers.
    
    Not only this is not needed, but this can also lead to wrong retrievals.
    
    For example, if the `u'…'` input is seen first, the `Markup('…')` output is cached. If later `Markup('…')` is seen, the retrieved value would have been `Markup('&…')`!
    
    Added a regression test for this example, `genshi.tests.output.cache_markup`.
    
    diff -r 69c74a6a19b4 genshi/output.py
    a b def _prepare_cache(use_cache=True): 
    9595            cache[kind, input] = output
    9696            return output
    9797        def _get(kind, input):
     98            if kind is TEXT and isinstance(input, Markup):
     99                return input
    98100            return cache.get((kind, input))
    99101    else:
    100102        def _emit(kind, input, output):
  • genshi/tests/output.py

    diff -r 69c74a6a19b4 genshi/tests/output.py
    a b import doctest 
    1515import unittest
    1616import sys
    1717
    18 from genshi.core import Attrs, Stream, QName
     18from genshi.core import Attrs, Markup, QName, Stream
    1919from genshi.input import HTML, XML
    2020from genshi.output import DocType, XMLSerializer, XHTMLSerializer, \
    2121                          HTMLSerializer, EmptyTagFilter
    class XMLSerializerTestCase(unittest.Tes 
    202202        output = XML(text).render(XMLSerializer, encoding=None)
    203203        self.assertEqual(text, output)
    204204
     205    def test_ignorable_space(self):
     206        text = '<foo> Mess  \n\n\n with me!  </foo>'
     207        output = XML(text).render(XMLSerializer, encoding=None)
     208        self.assertEqual('<foo> Mess\n with me!  </foo>', output)
     209
     210    def test_cache_markup(self):
     211        loc = (None, -1, -1)
     212        stream = Stream([(Stream.START, (QName('foo'), Attrs()), loc),
     213                         (Stream.TEXT, u'&hellip;', loc),
     214                         (Stream.END, QName('foo'), loc),
     215                         (Stream.START, (QName('bar'), Attrs()), loc),
     216                         (Stream.TEXT, Markup('&hellip;'), loc),
     217                         (Stream.END, QName('bar'), loc)])
     218        output = stream.render(XMLSerializer, encoding=None,
     219                               strip_whitespace=False)
     220        self.assertEqual('<foo>&amp;hellip;</foo><bar>&hellip;</bar>', output)
     221
    205222
    206223class XHTMLSerializerTestCase(unittest.TestCase):
    207224