Commits

Amaury Forgeot d'Arc  committed 76915c4

Allow unterminated utf7 sequences when final=False

  • Participants
  • Parent commits 363e840
  • Branches fast-forward

Comments (0)

Files changed (2)

File pypy/rlib/runicode.py

             result.append(unichr(oc))
             pos += 1
 
-    if inShift:
+    if inShift and final:
         endinpos = size
         msg = "unterminated shift sequence"
         res, pos = errorhandler(errors, 'utf-7', msg, s, startinpos, pos)

File pypy/rlib/test/test_runicode.py

         py.test.raises(UnicodeDecodeError, runicode.str_decode_utf_16_le,
                        s, len(s), True)
 
+    def test_utf7_partial(self):
+        s = u"a+-b".encode('utf-7')
+        assert s == "a+--b"
+        decode = self.getdecoder('utf-7')
+        assert decode(s, 1, None)[0] == u'a'
+        assert decode(s, 2, None)[0] == u'a'
+        assert decode(s, 3, None)[0] == u'a+'
+        assert decode(s, 4, None)[0] == u'a+-'
+        assert decode(s, 5, None)[0] == u'a+-b'
+
 
 class TestEncoding(UnicodeTests):
     def test_all_ascii(self):