GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — new Buffer doesn't handle unicode well · Issue #2344 · nodejs/node

new Buffer doesn't handle unicode well #2344

New issue
Copy link
New issue
Copy link
Closed
Closed
new Buffer doesn't handle unicode well#2344
Copy link
Labels
bufferIssues and PRs related to the buffer subsystem.docIssues and PRs related to Node.js documentation.i18n-apiIssues and PRs related to Node.js internationalization support.

Description

@calvinmetcalf
calvinmetcalf
opened on Aug 10, 2015
Issue body actions
var arr = [255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1]
//length 12;
var buf1 = new Buffer(arr)
// length 12
var hex1 = buf1.toString('hex');
// length 24
var str = buf1.toString('utf8')
// length 12
var buf2 = new Buffer(str);
//length 20
var hex2 = buf2.toString('hex');
// length 40;

results for hex2

browserify - efbfbd00104a4649460001 
node - efbfbdefbfbdefbfbdefbfbd00104a4649460001

the value of str in node is ����\u0000\u0010JFIF\u0000\u0001 which would suggest that the issue has to do with how new Buffer handles characters in text.

cc feross/buffer#66

Activity

  1. bnoordhuis commented on Aug 10, 2015

    @bnoordhuis
    bnoordhuis
    on Aug 10, 2015
    Member
    More actions

    255 is never valid in a UTF-8 byte sequence. It probably worked by accident but invalid UTF-8 is replaced with U+FFFD (the replacement character) as of node.js v0.10.29. The V8 UTF-8 decoder became stricter in v3.x so that might be a factor as well.

    I don't think there is anything to do here except make a note of it somewhere in the documentation..

  2. Fishrock123
    added
    bufferIssues and PRs related to the buffer subsystem.
    docIssues and PRs related to Node.js documentation.
    on Aug 10, 2015
  3. bnoordhuis commented on Aug 10, 2015

    @bnoordhuis
    bnoordhuis
    on Aug 10, 2015
    Member
    More actions

    U+FFFD (the replacement character)

    That's 0xEF 0xBF 0xBD as UTF-8, by the way; the repeated pattern you see in the test's output.

  4. mscdex
    changed the title [-]new Buffer doens't handle unicode well[/-] [+]new Buffer doesn't handle unicode well[/+] on Aug 10, 2015
  5. calvinmetcalf commented on Aug 11, 2015

    @calvinmetcalf
    calvinmetcalf
    on Aug 11, 2015
    ContributorAuthor
    More actions

    fixed on the browserify end

  6. calvinmetcalf
    closed this as completedon Aug 11, 2015
  7. srl295
    added
    i18n-apiIssues and PRs related to Node.js internationalization support.
    on Aug 13, 2015
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.docIssues and PRs related to Node.js documentation.i18n-apiIssues and PRs related to Node.js internationalization support.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.