Issue 22215: "embedded NUL character" exceptions (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/66411

classification

Title: "embedded NUL character" exceptions
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.5

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2014-08-17 14:43 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
valueerror_embedded_nul_character.diff serhiy.storchaka,2014-08-17 14:43 review
valueerror_embedded_nul_character_2.patch serhiy.storchaka,2014-09-05 09:50 review
valueerror_embedded_nul_character_3.patch serhiy.storchaka,2014-09-06 06:29 review
Messages (10)
msg225447 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-17 14:43
Currently most functions which accepts string only without embedded NUL character, raise TypeError. Proposed patch change exception type to more consistent ValueError. It also unifies error messages. I have opened a discussion on Python-Dev.
msg225518 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-19 07:02
BDFL have approved the idea (http://permalink.gmane.org/gmane.comp.python.devel/149000). Could anyone please make the review of concrete patch?
msg226403 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-05 07:07
If there are no objections I'll commit the patch soon.
msg226410 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-05 08:56
> If there are no objections I'll commit the patch soon. Replacing TypeError with ValueError is fine. TypeError was a bad choice. If an application relies on TypeError to check for null character, it's easy to replace "except TypeError:" with "except (TypeError, ValueError):" to stay compatible with Python < 3.5. Instead of "NUL character" (and "NUL byte), I had prefer "null character" (and "null byte"): http://en.wikipedia.org/wiki/Null_character I talking about the error message because you changed it in a few places.
msg226411 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-05 08:57
You may also take a look at these 2 issues: #13617 and #21147 (not directly related to this oe).
msg226413 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-05 09:50
Thank you Victor. Here is a patch which is synchronized with the tip and addresses your comment about a null character.
msg226472 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 06:21
Simplified a code in getargs.c as suggested by Victor.
msg226478 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-06 09:06
The latest patch looks good to me.
msg226495 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-09-06 17:08
New changeset 25032ec29315 by Serhiy Storchaka in branch 'default': Issue #22215: Now ValueError is raised instead of TypeError when str or bytes http://hg.python.org/cpython/rev/25032ec29315
msg226497 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-06 17:30
Thank you for your review Victor.
History
Date User Action Args
2022-04-11 14:58:07 admin set github: 66411
2014-09-06 17:31:30 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2014-09-06 17:30:58 serhiy.storchaka set messages: +
2014-09-06 17:08:25 python-dev set messages: +
2014-09-06 09:06:57 vstinner set messages: +
2014-09-06 06:29:27 serhiy.storchaka set files: + valueerror_embedded_nul_character_3.patch
2014-09-06 06:23:08 serhiy.storchaka set files: - valueerror_embedded_nul_character_3.patch
2014-09-06 06:21:39 serhiy.storchaka set files: + valueerror_embedded_nul_character_3.patchmessages: +
2014-09-05 09:50:37 serhiy.storchaka set files: + valueerror_embedded_nul_character_2.patchmessages: +
2014-09-05 08:57:48 vstinner set messages: +
2014-09-05 08:56:51 vstinner set nosy: + vstinnermessages: +
2014-09-05 07:07:03 serhiy.storchaka set messages: +
2014-08-30 20:59:51 r.david.murray set messages: -
2014-08-30 20:57:29 python-dev set nosy: + python-devmessages: +
2014-08-19 07:02:46 serhiy.storchaka set assignee: serhiy.storchaka
2014-08-19 07:02:20 serhiy.storchaka set messages: +
2014-08-17 14:43:54 serhiy.storchaka create