Skip to content

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

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

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

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
@ambv

ambv commented Apr 26, 2021

Copy link
Copy Markdown
Contributor

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