-
Notifications
You must be signed in to change notification settings - Fork 30k
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
buffer,string_decoder: consolidate encoding validation logic #7207
Conversation
I don't think this will work for |
Ok, let me take one more stab at it... |
} | ||
} | ||
if (!internalUtil) | ||
internalUtil = require('internal/util'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just include it at the top of the file. This is already being required by other modules prior to this point so there's no savings.
@mscdex ... ok, how does that look now? |
return enc; | ||
default: | ||
if (low) | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: this can be simplified to just return;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I did it this way just to make it more explicit. Either way works for me tho
LGTM except for minor nit. Should probably run this through citgm though just to be extra safe. |
CI: https://ci.nodejs.org/job/node-test-pull-request/2952/ ... Green except for unrelated build bot failure |
@@ -114,8 +114,7 @@ exports.normalizeEncoding = function normalizeEncoding(enc) { | |||
case 'hex': | |||
return enc; | |||
default: | |||
if (low) | |||
return undefined; | |||
if (low) return; // undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to add the comment we may as well just use return undefined;
;-)
loweredCase = true; | ||
} | ||
} | ||
Buffer[Symbol.for('isEncoding')] = Buffer.isEncoding = function(encoding) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say either
- Prefix the Symbol to help prevent collisions (e.g.
node.isEncoding
) - Create and export this symbol from
internal/util.js
so it's no longer global
I lean towards the later.
@trevnorris @mscdex ... updated and added a couple of tests. It turns out that we were not previously testing or verifying that |
LGTM |
LGTM if CI is still ok: https://ci.nodejs.org/job/node-test-pull-request/2988/ |
That CI run had a couple buildbot issues. Running again just to be safe |
Buffer.isEncoding and string_decoder.normalizeEncoding shared quite a bit of logic. This moves the primary logic into internal/util. The userland modules that monkey patch Buffer.isEncoding should still work.
873a028
to
7b459a9
Compare
New CI before landing... just in case.. https://ci.nodejs.org/job/node-test-pull-request/3038/ |
Buffer.isEncoding and string_decoder.normalizeEncoding shared quite a bit of logic. This moves the primary logic into internal/util. The userland modules that monkey patch Buffer.isEncoding should still work. PR-URL: #7207 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Landed in 6dd093d |
Returning different types of values from a function could have been avoided :( |
@thefourtheye What do you mean? |
@mscdex |
@thefourtheye How could it have been avoided? |
@mscdex maybe we could have returned an empty string instead of |
@thefourtheye Returning |
seems to have conflicts on v6 |
@Fishrock123 ... this PR builds on @mscdex's work in #6777. This can be backported to v6 if #6777 is. I don't believe a don't-land label is appropriate but we might need a better way of tracking dependencies between PRs. |
@jasnell That PR is already in v6, it's actually in v6.2.1. |
I put the don't land label for v4.x please correct if wrong |
steal a line from nodejs#7207 to make things work
steal a line from nodejs#7207 to make things work PR-URL: nodejs#8437 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
steal a line from nodejs#7207 to make things work PR-URL: nodejs#8437 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Buffer.isEncoding and string_decoder.normalizeEncoding shared quite a bit of logic. This moves the primary logic into internal/util. The userland modules that monkey patch Buffer.isEncoding should still work. PR-URL: nodejs#7207 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Buffer.isEncoding and string_decoder.normalizeEncoding shared quite a bit of logic. This moves the primary logic into internal/util. The userland modules that monkey patch Buffer.isEncoding should still work. PR-URL: #7207 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Refs: #8463 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Due to code consolidation in nodejs#7207 the isEncoding function got less strict. This commit makes sure isEncoding returns false for empty strings as before the consolidation. PR-URL: nodejs#18790 Refs: nodejs#7207 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Due to code consolidation in nodejs#7207 the isEncoding function got less strict. This commit makes sure isEncoding returns false for empty strings as before the consolidation. PR-URL: nodejs#18790 Refs: nodejs#7207 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Checklist
make -j4 test
(UNIX) orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
buffer, string_decoder
Description of change
Buffer.isEncoding and string_decoder.normalizeEncoding shared
quite a bit of logic. This moves the primary logic into
internal/util. The userland modules that monkey patch Buffer.isEncoding
should still work.
@nodejs/buffer @mscdex