Edgewall Software

Changeset 1164 for trunk


Ignore:
Timestamp:
Jun 12, 2011, 2:41:35 AM (12 years ago)
Author:
hodgestar
Message:

Don't cache (TEXT, Markup) events in serializers. This is not needed and since Markup instances compare equal to the same non-Markup string this can lead to incorrect cached output being retrieved. Fixes #429. This is patch t429-fix.2.patch from that ticket. It includes an additional unrelated test to check that the WhitespaceFilter? actually removes ignorable whitespace.

Location:
trunk/genshi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/genshi/output.py

    r1163 r1164  
    240240            stream = filter_(stream)
    241241        for kind, data, pos in stream:
     242            if kind is TEXT and isinstance(data, Markup):
     243                yield data
     244                continue
    242245            cached = _get((kind, data))
    243246            if cached is not None:
     
    346349            stream = filter_(stream)
    347350        for kind, data, pos in stream:
     351            if kind is TEXT and isinstance(data, Markup):
     352                yield data
     353                continue
    348354            cached = _get((kind, data))
    349355            if cached is not None:
     
    468474            stream = filter_(stream)
    469475        for kind, data, _ in stream:
     476            if kind is TEXT and isinstance(data, Markup):
     477                yield data
     478                continue
    470479            output = _get((kind, data))
    471480            if output is not None:
     
    659668
    660669        for kind, data, pos in stream:
     670            if kind is TEXT and isinstance(data, Markup):
     671                yield kind, data, pos
     672                continue
    661673            output = _get((kind, data))
    662674            if output is not None:
  • trunk/genshi/tests/output.py

    r1157 r1164  
    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, \
     
    362362        self.assertEqual('<!DOCTYPE html>\n<html></html>', output)
    363363
     364    def test_ignorable_space(self):
     365        text = '<foo> Mess  \n\n\n with me!  </foo>'
     366        output = XML(text).render(XMLSerializer, encoding=None)
     367        self.assertEqual('<foo> Mess\n with me!  </foo>', output)
     368
     369    def test_cache_markup(self):
     370        loc = (None, -1, -1)
     371        stream = Stream([(Stream.START, (QName('foo'), Attrs()), loc),
     372                         (Stream.TEXT, u'&hellip;', loc),
     373                         (Stream.END, QName('foo'), loc),
     374                         (Stream.START, (QName('bar'), Attrs()), loc),
     375                         (Stream.TEXT, Markup('&hellip;'), loc),
     376                         (Stream.END, QName('bar'), loc)])
     377        output = stream.render(XMLSerializer, encoding=None,
     378                               strip_whitespace=False)
     379        self.assertEqual('<foo>&amp;hellip;</foo><bar>&hellip;</bar>', output)
     380
    364381
    365382class HTMLSerializerTestCase(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.