Skip to content
Snippets Groups Projects
Commit f2b796e7 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

str.format: Don't assume that '}' immediately follows '{', skip insides.

That at least makes stuff like "{:x}".format(1) to produce not completely
broken output.
parent b99d9ea2
No related branches found
No related tags found
No related merge requests found
......@@ -270,7 +270,8 @@ mp_obj_t str_format(int n_args, const mp_obj_t *args) {
str++;
if (*str == '{') {
vstr_add_char(vstr, '{');
} else if (*str == '}') {
} else {
while (*str != '}') str++;
if (arg_i >= n_args) {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_IndexError, "tuple index out of range"));
}
......
print("{}-{}".format(1, [4, 5]))
print("{0}-{1}".format(1, [4, 5]))
print("{:x}".format(1))
print("{!r}".format(2))
# TODO
#print("{1}-{0}".format(1, [4, 5]))
#print("{:x}".format(0x10))
#print("{!r}".format("foo"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment