[pypy-commit] pypy default: Issue #2113: str.expandtabs(0)
arigo
noreply at buildbot.pypy.org
Thu Aug 13 16:57:07 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r78971:0b6868a4c2e2
Date: 2015-08-13 15:57 +0100
http://bitbucket.org/pypy/pypy/changeset/0b6868a4c2e2/
Log: Issue #2113: str.expandtabs(0)
diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -195,7 +195,8 @@
splitted = split(value, self._chr('\t'))
try:
- ovfcheck(len(splitted) * tabsize)
+ if tabsize > 0:
+ ovfcheck(len(splitted) * tabsize)
except OverflowError:
raise oefmt(space.w_OverflowError, "new string is too long")
expanded = oldtoken = splitted.pop(0)
@@ -210,6 +211,8 @@
def _tabindent(self, token, tabsize):
"""calculates distance behind the token to the next tabstop"""
+ if tabsize <= 0:
+ return 0
distance = tabsize
if token:
distance = 0
diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py
--- a/pypy/objspace/std/test/test_bytesobject.py
+++ b/pypy/objspace/std/test/test_bytesobject.py
@@ -388,6 +388,10 @@
skip("Wrong platform")
raises((MemoryError, OverflowError), 't\tt\t'.expandtabs, sys.maxint)
+ def test_expandtabs_0(self):
+ assert 'x\ty'.expandtabs(0) == 'xy'
+ assert 'x\ty'.expandtabs(-42) == 'xy'
+
def test_splitlines(self):
s = ""
assert s.splitlines() == []
diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -494,6 +494,10 @@
skip("Wrong platform")
raises((OverflowError, MemoryError), u't\tt\t'.expandtabs, sys.maxint)
+ def test_expandtabs_0(self):
+ assert u'x\ty'.expandtabs(0) == u'xy'
+ assert u'x\ty'.expandtabs(-42) == u'xy'
+
def test_translate(self):
assert u'bbbc' == u'abababc'.translate({ord('a'):None})
assert u'iiic' == u'abababc'.translate({ord('a'):None, ord('b'):ord('i')})
More information about the pypy-commit
mailing list