From: <pj...@us...> - 2009-06-06 20:51:41
|
Revision: 6460 http://jython.svn.sourceforge.net/jython/?rev=6460&view=rev Author: pjenvey Date: 2009-06-06 20:50:29 +0000 (Sat, 06 Jun 2009) Log Message: ----------- fix utf8/utf16 decoders stateful mode argument being switched around fixes #1368 Modified Paths: -------------- trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/src/org/python/modules/_codecs.java Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2009-06-06 13:07:39 UTC (rev 6459) +++ trunk/jython/Lib/test/test_unicode_jy.py 2009-06-06 20:50:29 UTC (rev 6460) @@ -82,6 +82,11 @@ self.assertEqual(float(u'\u0663.\u0661'), 3.1) self.assertEqual(complex(u'\u0663.\u0661'), 3.1+0j) + def test_unstateful_end_of_data(self): + # http://bugs.jython.org/issue1368 + for encoding in 'utf-8', 'utf-16', 'utf-16-be', 'utf-16-le': + self.assertRaises(UnicodeDecodeError, '\xe4'.decode, encoding) + def test_formatchar(self): self.assertEqual('%c' % 255, '\xff') self.assertRaises(OverflowError, '%c'.__mod__, 256) Modified: trunk/jython/src/org/python/modules/_codecs.java =================================================================== --- trunk/jython/src/org/python/modules/_codecs.java 2009-06-06 13:07:39 UTC (rev 6459) +++ trunk/jython/src/org/python/modules/_codecs.java 2009-06-06 20:50:29 UTC (rev 6460) @@ -67,9 +67,9 @@ } public static PyTuple utf_8_decode(String str, String errors, boolean final_) { - int[] consumed = final_ ? new int[1] : null; + int[] consumed = final_ ? null : new int[1]; return decode_tuple(codecs.PyUnicode_DecodeUTF8Stateful(str, errors, consumed), - final_ ? consumed[0] : str.length()); + final_ ? str.length() : consumed[0]); } public static PyTuple utf_8_encode(String str) { @@ -431,9 +431,9 @@ public static PyTuple utf_16_decode(String str, String errors, boolean final_) { int[] bo = new int[] { 0 }; - int[] consumed = final_ ? new int[1] : null; + int[] consumed = final_ ? null : new int[1]; return decode_tuple(decode_UTF16(str, errors, bo, consumed), - final_ ? consumed[0] : str.length()); + final_ ? str.length() : consumed[0]); } public static PyTuple utf_16_le_decode(String str) { @@ -446,9 +446,9 @@ public static PyTuple utf_16_le_decode(String str, String errors, boolean final_) { int[] bo = new int[] { -1 }; - int[] consumed = final_ ? new int[1] : null; + int[] consumed = final_ ? null : new int[1]; return decode_tuple(decode_UTF16(str, errors, bo, consumed), - final_ ? consumed[0] : str.length()); + final_ ? str.length() : consumed[0]); } public static PyTuple utf_16_be_decode(String str) { @@ -461,9 +461,9 @@ public static PyTuple utf_16_be_decode(String str, String errors, boolean final_) { int[] bo = new int[] { 1 }; - int[] consumed = final_ ? new int[1] : null; + int[] consumed = final_ ? null : new int[1]; return decode_tuple(decode_UTF16(str, errors, bo, consumed), - final_ ? consumed[0] : str.length()); + final_ ? str.length() : consumed[0]); } public static PyTuple utf_16_ex_decode(String str) { @@ -481,10 +481,10 @@ public static PyTuple utf_16_ex_decode(String str, String errors, int byteorder, boolean final_) { int[] bo = new int[] { 0 }; - int[] consumed = final_ ? new int[1] : null; + int[] consumed = final_ ? null : new int[1]; String decoded = decode_UTF16(str, errors, bo, consumed); return new PyTuple(Py.newString(decoded), - Py.newInteger(final_ ? consumed[0] : str.length()), + Py.newInteger(final_ ? str.length() : consumed[0]), Py.newInteger(bo[0])); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |