From: <fwi...@us...> - 2009-02-19 20:16:25
|
Revision: 6040 http://jython.svn.sourceforge.net/jython/?rev=6040&view=rev Author: fwierzbicki Date: 2009-02-19 20:16:18 +0000 (Thu, 19 Feb 2009) Log Message: ----------- Our handling of writes after a seek beyond the end of cStringIO was not consistent with CPython (or even our own use of StringIO). Found while trying to get Mercurial to respond to "hg log". Modified Paths: -------------- trunk/jython/Lib/test/test_StringIO_jy.py trunk/jython/src/org/python/modules/cStringIO.java Modified: trunk/jython/Lib/test/test_StringIO_jy.py =================================================================== --- trunk/jython/Lib/test/test_StringIO_jy.py 2009-02-18 13:21:13 UTC (rev 6039) +++ trunk/jython/Lib/test/test_StringIO_jy.py 2009-02-19 20:16:18 UTC (rev 6040) @@ -20,6 +20,14 @@ f.write('hi') self.assertEquals(f.getvalue(), 'hehio') + #XXX: this should get pushed to CPython's test_StringIO + def test_write_past_end(self): + f = cStringIO.StringIO() + f.write("abcdef") + f.seek(10) + f.write("uvwxyz") + self.assertEqual(f.getvalue(), 'abcdef\x00\x00\x00\x00uvwxyz') + def test_main(): test_support.run_unittest(TestUnicodeInput) test_support.run_unittest(TestWrite) Modified: trunk/jython/src/org/python/modules/cStringIO.java =================================================================== --- trunk/jython/src/org/python/modules/cStringIO.java 2009-02-18 13:21:13 UTC (rev 6039) +++ trunk/jython/src/org/python/modules/cStringIO.java 2009-02-19 20:16:18 UTC (rev 6040) @@ -350,12 +350,17 @@ int newpos = spos + s.length(); - if (newpos > slen) { - buf.replace(spos, slen - spos, s); - buf.append(s.substring(slen)); + if (spos < slen) { + if (newpos > slen) { + buf.replace(spos, slen - spos, s); + buf.append(s.substring(slen)); + slen = newpos; + } else { + buf.replace(spos, spos + s.length(), s); + } + } else { + buf.append(s); slen = newpos; - } else { - buf.replace(spos, spos + s.length(), s); } buf.setLength(slen); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |