Don't decode bytes (which may not be UTF8) when displaying SecretBytes#8012
Don't decode bytes (which may not be UTF8) when displaying SecretBytes#8012adriangb merged 1 commit intopydantic:mainfrom
Conversation
|
please review |
Pinging @adriangb because I wrote the above in an edit and I don't know if that triggers a notification. |
adriangb
left a comment
There was a problem hiding this comment.
I don’t see any problem with this. In not sure why I did that in that commit, may have been carryover from moving files or something. I don’t see the decode() call in v1
|
Mind adding a small release note as a bug fix? |
Where would I add that? I can't see anything in https://docs.pydantic.dev/latest/contributing/ and adding to |
|
I guess we just use a tag on the PR now |
Change Summary
Removes unneeded
.decode().I couldn't find any justification for decoding the bytes. The code was introduced in this commit in #5674 and I don't see any PR comments explaining it. @adriangb any idea?
There are some encodings where a non-empty byte string can decode to any empty string:
but
.decode()without arguments should always use UTF8 in Python 3 regardless of locale settings.I've checked that any non-empty byte string with up to 3 bytes decodes to a non-empty string if it can be decoded at all:
I also think that any non-empty byte string should be treated as non-empty when displaying even if it can be decoded to an empty unicode string. Although I'm also not sure about revealing whether any secret value is empty.
Related issue number
Closes #7971
Checklist
Selected Reviewer: @lig