Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
felixge opened this Issue Dec 31, 2011 · 3 comments

Comments

Projects
None yet
3 participants

felixge commented Dec 31, 2011

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.

Owner

bnoordhuis commented Dec 31, 2011

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 commented Jan 5, 2012

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

@koichik koichik closed this Jan 5, 2012

felixge commented Jan 5, 2012

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