summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorMichaelSaah <mike.saah@gmail.com>2019-01-14 05:23:39 -0500
committerVictor Stinner <vstinner@redhat.com>2019-01-14 11:23:39 +0100
commit454b3d4ea246e8751534e105548d141ed7b0b032 (patch)
tree6a337c41728d51a65521e0a9b47176654775cfd4 /Modules
parent5bb146aaea1484bcc117ab6cb38dda39ceb5df0f (diff)
downloadcpython-git-454b3d4ea246e8751534e105548d141ed7b0b032.tar.gz
bpo-35066: _dateime.datetime.strftime copies trailing '%' (GH-10692)
Previously, calling the strftime() method on a datetime object with a trailing '%' in the format string would result in an exception. However, this only occured when the datetime C module was being used; the python implementation did not match this behavior. Datetime is now PEP-399 compliant, and will not throw an exception on a trailing '%'.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_datetimemodule.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 16c7bffda8..7997758908 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1528,10 +1528,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
ntoappend = 1;
}
else if ((ch = *pin++) == '\0') {
- /* There's a lone trailing %; doesn't make sense. */
- PyErr_SetString(PyExc_ValueError, "strftime format "
- "ends with raw %");
- goto Done;
+ /* Null byte follows %, copy only '%'.
+ *
+ * Back the pin up one char so that we catch the null check
+ * the next time through the loop.*/
+ pin--;
+ ptoappend = pin - 1;
+ ntoappend = 1;
}
/* A % has been seen and ch is the character after it. */
else if (ch == 'z') {
@@ -1616,7 +1619,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
usednew += ntoappend;
assert(usednew <= totalnew);
} /* end while() */
-
+
if (_PyBytes_Resize(&newfmt, usednew) < 0)
goto Done;
{