Skip to content

Commit 43c337e

Browse files
committed
throw TypeError if str or bytes % operator gets too many arguments
1 parent d399bb8 commit 43c337e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,15 @@ def test_bytes_init():
706706
bytes.__init__(ba, b'zzz')
707707
assert ba == bytes(b'abc')
708708

709+
def test_bytes_mod():
710+
assert b'%s' % (b'a') == b'a'
711+
raised = False
712+
try:
713+
b'%s' % (b'a', b'b')
714+
except TypeError:
715+
raised = True
716+
assert raised
717+
709718
class BaseLikeBytes:
710719

711720
def test_maketrans(self):

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ private T formatImpl(Object args1) {
490490
* of range; if a special value, it would be wrong if it were -1, indicating a single item
491491
* that has not yet been used.
492492
*/
493-
if (argIndex == -1 || (argIndex >= 0 && PythonObjectLibrary.getUncached().length(args1) > argIndex + 1)) {
493+
if (argIndex == -1 || (argIndex >= 0 && PythonObjectLibrary.getUncached().length(args1) >= argIndex + 1)) {
494494
throw core.raise(TypeError, ErrorMessages.NOT_ALL_ARGS_CONVERTED_DURING_FORMATTING, getFormatType());
495495
}
496496

0 commit comments

Comments
 (0)