X Tutup
The Wayback Machine - https://web.archive.org/web/20250702013923/https://github.com/python/cpython/pull/24729
Skip to content

[3.8] bpo-43295: Fix error handling of datetime.strptime format string '%z' (GH-24627) #24729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Mar 3, 2021

Previously, datetime.strptime would match 'z' with the format string '%z' (for UTC offsets), throwing an IndexError by erroneously trying to parse 'z' as a timestamp. As a special case, '%z' matches the string 'Z' which is equivalent to the offset '+00:00', however this behavior is not defined for lowercase 'z'.

This change ensures a ValueError is thrown when encountering the original example, as follows:

>>> from datetime import datetime
>>> datetime.strptime('z', '%z')
ValueError: time data 'z' does not match format '%z'

Automerge-Triggered-By: GH:pganssle
(cherry picked from commit 04f6fbb)

Co-authored-by: Noor Michael nsmichael31@gmail.com

https://bugs.python.org/issue43295

…pythonGH-24627)

Previously, `datetime.strptime` would match `'z'` with the format string `'%z'` (for UTC offsets), throwing an `IndexError` by erroneously trying to parse `'z'` as a timestamp. As a special case, `'%z'` matches the string `'Z'` which is equivalent to the offset `'+00:00'`, however this behavior is not defined for lowercase `'z'`.

This change ensures a `ValueError` is thrown when encountering the original example, as follows:

```
>>> from datetime import datetime
>>> datetime.strptime('z', '%z')
ValueError: time data 'z' does not match format '%z'
```

Automerge-Triggered-By: GH:pganssle
(cherry picked from commit 04f6fbb)

Co-authored-by: Noor Michael <nsmichael31@gmail.com>
@miss-islington
Copy link
Contributor Author

@noormichael: Status check is done, and it's a success ✅ .

@github-actions
Copy link

github-actions bot commented Apr 3, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 3, 2021
@ambv
Copy link
Contributor

ambv commented Apr 26, 2021

Closing this stale backport as the 3.8 is nearing to security-fix only mode.

@ambv ambv closed this Apr 26, 2021
@miss-islington miss-islington deleted the backport-04f6fbb-3.8 branch April 26, 2021 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
X Tutup