Skip to content

Commit b648e98

Browse files
committed
py/objstr: Fix error reporting for unexpected end of modulo format str.
1 parent 7ef75f9 commit b648e98

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

py/objstr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
12991299
continue;
13001300
}
13011301
if (++str >= top) {
1302-
break;
1302+
goto incomplete_format;
13031303
}
13041304
if (*str == '%') {
13051305
vstr_add_byte(&vstr, '%');
@@ -1369,6 +1369,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
13691369
}
13701370

13711371
if (str >= top) {
1372+
incomplete_format:
13721373
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
13731374
terse_str_format_value_error();
13741375
} else {

tests/basics/string_format_modulo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,8 @@
111111
'%l' % 1
112112
except ValueError:
113113
print('ValueError')
114+
115+
try:
116+
'a%' % 1
117+
except ValueError:
118+
print('ValueError')

0 commit comments

Comments
 (0)