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

Fill Character cannot be \0 #61905

Closed
Julian mannequin opened this issue Apr 12, 2013 · 6 comments
Closed

Fill Character cannot be \0 #61905

Julian mannequin opened this issue Apr 12, 2013 · 6 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@Julian
Copy link
Mannequin

Julian mannequin commented Apr 12, 2013

BPO 17705
Nosy @mdickinson, @ericvsmith, @skrah, @Julian
Superseder
  • bpo-12546: builtin format methods cannot fill with \x00 char
  • Files
  • cpython-3.3-17705.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/ericvsmith'
    closed_at = <Date 2014-04-03.16:14:29.399>
    created_at = <Date 2013-04-12.16:54:55.169>
    labels = ['interpreter-core', 'type-bug']
    title = 'Fill Character cannot be \\0'
    updated_at = <Date 2014-04-03.16:15:23.957>
    user = 'https://github.com/Julian'

    bugs.python.org fields:

    activity = <Date 2014-04-03.16:15:23.957>
    actor = 'skrah'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2014-04-03.16:14:29.399>
    closer = 'skrah'
    components = ['Interpreter Core']
    creation = <Date 2013-04-12.16:54:55.169>
    creator = 'Julian'
    dependencies = []
    files = ['29827']
    hgrepos = []
    issue_num = 17705
    keywords = ['patch']
    message_count = 6.0
    messages = ['186653', '186724', '186726', '186731', '186842', '215456']
    nosy_count = 5.0
    nosy_names = ['mark.dickinson', 'eric.smith', 'skrah', 'Julian', 'Jason.Michalski']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '12546'
    type = 'behavior'
    url = 'https://bugs.python.org/issue17705'
    versions = ['Python 3.4', 'Python 3.5']

    @Julian
    Copy link
    Mannequin Author

    Julian mannequin commented Apr 12, 2013

    The docs say:

    "The fill character can be any character other than ‘{‘ or ‘}’."

    http://docs.python.org/dev/library/string.html#format-specification-mini-language

    But:

    >>> "{0:\x01>8.2f}".format(12)
    '\x01\x01\x0112.00'

    whereas:

    >>> "{0:\x00>8.2f}".format(12)
    '   12.00'

    @Julian Julian mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 12, 2013
    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Apr 13, 2013

    Unsurprisingly (libmpdec is a C library) this also does not work in _decimal. I could add a special case in _decimal.c at the cost of
    two additional if statements for all regular use cases.

    Is padding with NUL a legitimate use case? IOW, is the slowdown justified?

    @mdickinson
    Copy link
    Member

    Is padding with NUL a legitimate use case?

    I don't see a good reason to disallow it, and it seems like a fairly plausible need. Numpy, for example, pads strings will NUL bytes when placing a short string in long fixed-width field.

    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Apr 13, 2013

    Mark Dickinson <report@bugs.python.org> wrote:

    Numpy, for example, pads strings will NUL bytes when placing a short
    string in long fixed-width field.

    I was hoping to escape the work, but that's quite convincing. ;)

    Changing libmpdec doesn't look very appealing, so probably I'll use
    "{" as a placeholder for NUL and then rewrite the result.

    @JasonMichalski
    Copy link
    Mannequin

    JasonMichalski mannequin commented Apr 13, 2013

    I worked on a patch that allows NUL padding for longs, floats and complex numbers. It seems NUL was being used as a sentinel in the format string parsing when no padding character is given. It was then replaced with a space in each call to fill_padding if it was NUL.

    @ericvsmith ericvsmith self-assigned this Apr 13, 2013
    @skrah
    Copy link
    Mannequin

    skrah mannequin commented Apr 3, 2014

    This looks like a duplicate of bpo-12546.

    @skrah skrah mannequin closed this as completed Apr 3, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants