summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-08-26 15:45:06 +0100
committerDamien George <damien.p.george@gmail.com>2015-08-29 23:13:51 +0100
commitb648e98ad01d7f5c4aa102c4848507b5c31c859e (patch)
treeba681490d60f2adf0cf12e93bc599ed1a5671e1c
parent7ef75f9f750da6f1a7f149bc6cd8c28f1d9cad50 (diff)
downloadmicropython-b648e98ad01d7f5c4aa102c4848507b5c31c859e.tar.gz
micropython-b648e98ad01d7f5c4aa102c4848507b5c31c859e.zip
py/objstr: Fix error reporting for unexpected end of modulo format str.
-rw-r--r--py/objstr.c3
-rw-r--r--tests/basics/string_format_modulo.py5
2 files changed, 7 insertions, 1 deletions
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')