From 12ebefc9d3b7268d17d4a042767f712c46d03dfe Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Mon, 18 Jul 2011 14:03:41 -0400 Subject: Closes #12579. Positional fields with str.format_map() now raise a ValueError instead of SystemError. --- Objects/stringlib/string_format.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Objects/stringlib/string_format.h') diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index 6f10727e245..6c7adcb01ed 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -511,6 +511,16 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs, Py_DECREF(key); } else { + /* If args is NULL, we have a format string with a positional field + with only kwargs to retrieve it from. This can only happen when + used with format_map(), where positional arguments are not + allowed. */ + if (args == NULL) { + PyErr_SetString(PyExc_ValueError, "Format string contains " + "positional fields"); + goto error; + } + /* look up in args */ obj = PySequence_GetItem(args, index); if (obj == NULL) -- cgit v1.2.3