Skip to content
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

"embedded NUL character" exceptions #66411

Closed
serhiy-storchaka opened this issue Aug 17, 2014 · 10 comments
Closed

"embedded NUL character" exceptions #66411

serhiy-storchaka opened this issue Aug 17, 2014 · 10 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 22215
Nosy @vstinner, @serhiy-storchaka
Files
  • valueerror_embedded_nul_character.diff
  • valueerror_embedded_nul_character_2.patch
  • valueerror_embedded_nul_character_3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-09-06.17:31:30.354>
    created_at = <Date 2014-08-17.14:43:54.964>
    labels = ['interpreter-core', 'type-feature']
    title = '"embedded NUL character" exceptions'
    updated_at = <Date 2014-09-06.17:31:30.353>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2014-09-06.17:31:30.353>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-09-06.17:31:30.354>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2014-08-17.14:43:54.964>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['36394', '36546', '36557']
    hgrepos = []
    issue_num = 22215
    keywords = ['patch']
    message_count = 10.0
    messages = ['225447', '225518', '226403', '226410', '226411', '226413', '226472', '226478', '226495', '226497']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22215'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Aug 17, 2014
    @serhiy-storchaka
    Copy link
    Member Author

    BDFL have approved the idea (http://permalink.gmane.org/gmane.comp.python.devel/149000). Could anyone please make the review of concrete patch?

    @serhiy-storchaka serhiy-storchaka self-assigned this Aug 19, 2014
    @serhiy-storchaka
    Copy link
    Member Author

    If there are no objections I'll commit the patch soon.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 5, 2014

    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.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 5, 2014

    You may also take a look at these 2 issues: bpo-13617 and bpo-21147 (not directly related to this oe).

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you Victor. Here is a patch which is synchronized with the tip and addresses your comment about a null character.

    @serhiy-storchaka
    Copy link
    Member Author

    Simplified a code in getargs.c as suggested by Victor.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2014

    The latest patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 6, 2014

    New changeset 25032ec29315 by Serhiy Storchaka in branch 'default':
    Issue bpo-22215: Now ValueError is raised instead of TypeError when str or bytes
    http://hg.python.org/cpython/rev/25032ec29315

    @serhiy-storchaka
    Copy link
    Member Author

    Thank you for your review Victor.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants