Skip to content

buffer: inconsistent string validation #3770

Description

@vkurchatkin
new Buffer('x', 'hex') // TypeError: Invalid hex string
new Buffer('xx', 'hex') // <Buffer >

This seems confusing

Activity

  1. added
    bufferIssues and PRs related to the buffer subsystem.
    on Nov 11, 2015
  2. Trott commented on Jun 6, 2016

    @Trott
    Member

    If it matters, the underlying issue is in Buffer.prototype.write() (which is called by the constructor in this case) and not specific to the constructor.

    buf = new Buffer(64);
    buf.write('x', 'hex'); // TypeError: Invalid hex string
    buf.write('xx', 'hex'); // 0
  3. Trott commented on Mar 23, 2017

    @Trott
    Member

    Additionally, it seems to me that TypeError is the wrong error to throw here. A TypeError might be if something that was not a string was supplied. But an incorrectly formatted string is not a TypeError, or at least it seems to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions