Commit b648e98a authored by Damien George's avatar Damien George
Browse files

py/objstr: Fix error reporting for unexpected end of modulo format str.

parent 7ef75f9f
...@@ -1299,7 +1299,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o ...@@ -1299,7 +1299,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
continue; continue;
} }
if (++str >= top) { if (++str >= top) {
break; goto incomplete_format;
} }
if (*str == '%') { if (*str == '%') {
vstr_add_byte(&vstr, '%'); 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 ...@@ -1369,6 +1369,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
} }
if (str >= top) { if (str >= top) {
incomplete_format:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
terse_str_format_value_error(); terse_str_format_value_error();
} else { } else {
......
...@@ -111,3 +111,8 @@ try: ...@@ -111,3 +111,8 @@ try:
'%l' % 1 '%l' % 1
except ValueError: except ValueError:
print('ValueError') print('ValueError')
try:
'a%' % 1
except ValueError:
print('ValueError')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment