From b648e98ad01d7f5c4aa102c4848507b5c31c859e Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 26 Aug 2015 15:45:06 +0100 Subject: [PATCH] py/objstr: Fix error reporting for unexpected end of modulo format str. --- py/objstr.c | 3 ++- tests/basics/string_format_modulo.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/py/objstr.c b/py/objstr.c index 98360d9e11..f91e1731c5 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1299,7 +1299,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o continue; } if (++str >= top) { - break; + goto incomplete_format; } if (*str == '%') { 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 } if (str >= top) { +incomplete_format: if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { terse_str_format_value_error(); } else { diff --git a/tests/basics/string_format_modulo.py b/tests/basics/string_format_modulo.py index 05b00ef14f..2e4909220a 100644 --- a/tests/basics/string_format_modulo.py +++ b/tests/basics/string_format_modulo.py @@ -111,3 +111,8 @@ try: '%l' % 1 except ValueError: print('ValueError') + +try: + 'a%' % 1 +except ValueError: + print('ValueError')