Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Buffer#write adds trailing 0x00 for utf-8 but not ascii #2446

Closed
felixge opened this Issue · 3 comments

3 participants

@felixge
Owner

I'd love to fix this (make it consistent), but first I'm wondering if anybody has comments on this:

When writing out a 'utf-8' string, it gets a terminating 0x00 (C-Style String):

> buffer = new Buffer([255, 255, 255])
<Buffer ff ff ff>
> buffer.write('Ö', 'utf-8')
2
> buffer
<Buffer c3 96 00>

However, when writing out a string using 'ascii' encoding, no trailing 0x00 is added:

> buffer = new Buffer([255, 255, 255])
<Buffer ff ff ff>
> buffer.write('Oe', 'ascii')
2
> buffer
<Buffer 4f 65 ff>

IMO this is very inconsistent. Personally I'd favor never adding a trailing 0x00 since the underlaying assumption (everything is stored as a 0x00-terminated string) is not true.

@bnoordhuis

What version of Node are you seeing this with, Felix? v0.6 and master both use NO_NULL_TERMINATION. To wit:

$ v0.6/out/Debug/node 
> buffer = new Buffer([255, 255, 255])
<Buffer ff ff ff>
> buffer.write('Ö', 'utf-8')
2
> buffer
<Buffer c3 96 ff>
@koichik
Owner

Yes, this has fixed in 6a72e52. See also #394 and #1902.
Closing.

@koichik koichik closed this
@felixge
Owner

What version of Node are you seeing this with, Felix? v0.6 and master both use NO_NULL_TERMINATION. To wit:

Yeah, sorry I was testing with node 0.4.12, it's fixed in 0.6. I can work around it in 0.4.x so I guess it doesn't need backporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.