From: <fel...@us...> - 2005-03-27 15:05:46
|
Author: felixwiemann Date: 2005-03-27 17:05:34 +0200 (Sun, 27 Mar 2005) New Revision: 3138 Added: trunk/docutils/test/test_io.py Modified: trunk/docutils/docutils/io.py Log: remove BOMs from input streams Modified: trunk/docutils/docutils/io.py =================================================================== --- trunk/docutils/docutils/io.py 2005-03-27 14:22:09 UTC (rev 3137) +++ trunk/docutils/docutils/io.py 2005-03-27 15:05:34 UTC (rev 3138) @@ -95,7 +95,8 @@ try: decoded = unicode(data, enc, self.error_handler) self.successful_encoding = enc - return decoded + # Return decoded, removing BOMs. + return decoded.replace(u'\ufeff', u'') except (UnicodeError, LookupError), error: pass if error is not None: Added: trunk/docutils/test/test_io.py =================================================================== --- trunk/docutils/test/test_io.py 2005-03-27 14:22:09 UTC (rev 3137) +++ trunk/docutils/test/test_io.py 2005-03-27 15:05:34 UTC (rev 3138) @@ -0,0 +1,27 @@ +#! /usr/bin/env python + +# Author: Felix Wiemann +# Contact: Fel...@os... +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. + +""" +Test module for io.py. +""" + +import unittest +from docutils import io + + +class InputTests(unittest.TestCase): + + def test_bom(self): + input = io.StringInput(source='\xef\xbb\xbf foo \xef\xbb\xbf bar', + encoding='utf8') + # Assert BOMs are gone. + self.assertEquals(input.read(), u' foo bar') + + +if __name__ == '__main__': + unittest.main() Property changes on: trunk/docutils/test/test_io.py ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native |