buffer,string_decoder: consolidate encoding validation logic#7207
buffer,string_decoder: consolidate encoding validation logic#7207jasnell wants to merge 1 commit intonodejs:masterfrom
Conversation
|
I don't think this will work for |
|
Ok, let me take one more stab at it... |
lib/buffer.js
Outdated
There was a problem hiding this comment.
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? |
lib/internal/util.js
Outdated
There was a problem hiding this comment.
minor nit: this can be simplified to just return;
There was a problem hiding this comment.
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 |
lib/internal/util.js
Outdated
There was a problem hiding this comment.
If we're going to add the comment we may as well just use return undefined; ;-)
lib/buffer.js
Outdated
There was a problem hiding this comment.
I'd say either
- Prefix the Symbol to help prevent collisions (e.g.
node.isEncoding) - Create and export this symbol from
internal/util.jsso 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