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

doc: fix misleading ASCII comments #11657

Closed
wants to merge 1 commit into from

Conversation

rahatarmanahmed
Copy link
Contributor

Fixed a couple of misleading references to ASCII for default encoding examples (should be UTF-8).

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations. labels Mar 2, 2017
const buf6 = Buffer.from('tést', 'utf8');
const buf5 = Buffer.from('tést');

// Creates a Buffer containing ASCII bytes [0x74, 0xe9, 0x73, 0x74].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not ASCII bytes, though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, did I make an error in the result?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ASCII encoding uses only the bytes up to 127, and it can’t encode characters such as é at all. In some places of the API – like Buffer.from(…, 'ascii') – Node just treats ascii like latin-1 for performance reasons, where é maps to 0xe9. That doesn’t always work, though; for example:

> Buffer.from('tést', 'ascii').toString('ascii')
'tist'

If you want to use this example, I’d suggest going with something like Latin-1 bytes, and use Buffer.from(…, 'latin-1').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, wasn't aware of that. I'll change it to latin-1.

@@ -38,11 +38,11 @@ const buf3 = Buffer.allocUnsafe(10);
// Creates a Buffer containing [0x1, 0x2, 0x3].
const buf4 = Buffer.from([1, 2, 3]);

// Creates a Buffer containing ASCII bytes [0x74, 0x65, 0x73, 0x74].
const buf5 = Buffer.from('test');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this example? I think I can see where this is coming from, but it might be better to just replace ASCII with ASCII/UTF-8 in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that it's more consistent with the other examples in the doc, and also shows the difference between the two encodings that will affect the output ('test' is the same in ascii and utf8 but not 'tést'). That may or may not be important

Just changing the text to ASCII/UTF-8 is still an improvement but I think this example is clearer.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me!

@addaleax
Copy link
Member

addaleax commented Mar 5, 2017

Landed in bbc118f, thanks for the PR! 🎉

@addaleax addaleax closed this Mar 5, 2017
addaleax pushed a commit that referenced this pull request Mar 5, 2017
PR-URL: #11657
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
addaleax pushed a commit that referenced this pull request Mar 5, 2017
PR-URL: #11657
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
@evanlucas evanlucas mentioned this pull request Mar 8, 2017
MylesBorins pushed a commit that referenced this pull request Apr 17, 2017
PR-URL: #11657
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
@MylesBorins
Copy link
Contributor

backported to v6.x... lmk if I was mistaken to do so

MylesBorins pushed a commit that referenced this pull request Apr 19, 2017
PR-URL: #11657
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
@MylesBorins MylesBorins mentioned this pull request Apr 19, 2017
andrew749 pushed a commit to michielbaird/node that referenced this pull request Jul 19, 2017
PR-URL: nodejs/node#11657
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants