Skip to content

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

Closed
miss-islington wants to merge 1 commit into
python:3.9from
miss-islington:backport-04f6fbb-3.9
Closed

[3.9] bpo-43295: Fix error handling of datetime.strptime format string '%z' (GH-24627)#24728
miss-islington wants to merge 1 commit into
python:3.9from
miss-islington:backport-04f6fbb-3.9

Conversation

@miss-islington

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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

@github-actions

github-actions Bot commented Apr 3, 2021

Copy link
Copy Markdown

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
@vstinner vstinner closed this Apr 28, 2021
@miss-islington miss-islington deleted the backport-04f6fbb-3.9 branch April 28, 2021 16:23
@vstinner

Copy link
Copy Markdown
Member

I created a new backport PR: PR #25695.

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