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

src: fix erroneous fallthrough in ParseEncoding() #7262

Merged
merged 2 commits into from
Jun 13, 2016

Conversation

bnoordhuis
Copy link
Member

@bnoordhuis bnoordhuis commented Jun 10, 2016

A missing 'break' statement unintentionally allowed "linary"
and "luffer" as alternatives for "binary" and "buffer".

Regression introduced in commit 54cc721 ("buffer: introduce latin1
encoding term".)

R=@trevnorris

CI: https://ci.nodejs.org/job/node-test-pull-request/2972/

@bnoordhuis bnoordhuis added c++ Issues and PRs that require attention from people who are familiar with C++. test Issues and PRs related to the tests. lib / src Issues and PRs related to general changes in the lib or src directory. labels Jun 10, 2016
@@ -143,11 +143,15 @@ ADDONS_BINDING_GYPS := \
$(filter-out test/addons/??_*/binding.gyp, \
$(wildcard test/addons/*/binding.gyp))

ADDONS_BINDING_SOURCES := \
$(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \
$(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) \
Copy link
Member

Choose a reason for hiding this comment

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

tiny nit: the trailing \ here is superfluous/inconsistent with the way line continuations are ended in the rest of the Makefile

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to write it like that because it keeps the diff small when you add lines later on. But you're right, the rest of the Makefile doesn't use that style.

@addaleax
Copy link
Member

LGTM

@thefourtheye
Copy link
Contributor

Shouldn't the if..else if...else ladder below be fixed? Right now it returns BINARY if the case-insensitive comparison is truthy

   } else if (StringEqualNoCase(encoding, "latin1")) {
     return LATIN1;
   } else if (StringEqualNoCase(encoding, "binary")) {
     return BINARY;    // HERE
   } else if (StringEqualNoCase(encoding, "buffer")) {
     return BUFFER;

I think it should be

   } else if (StringEqualNoCase(encoding, "latin1")) {
     return LATIN1;
   } else if (StringEqualNoCase(encoding, "binary")) {
     return LATIN1;    // HERE
   } else if (StringEqualNoCase(encoding, "buffer")) {
     return BUFFER;

@jasnell
Copy link
Member

jasnell commented Jun 10, 2016

LGTM
@thefourtheye ... it likely could be but not sure it has to be.

@bnoordhuis
Copy link
Member Author

I think @thefourtheye is on to something. It wouldn't matter except that BINARY and LATIN1 are different values.

@trevnorris Can you comment on whether this patch makes sense?

diff --git a/src/node.h b/src/node.h
index d813b45..427f45d 100644
--- a/src/node.h
+++ b/src/node.h
@@ -278,7 +278,7 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv,
 }
 #define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD

-enum encoding {ASCII, UTF8, BASE64, UCS2, LATIN1, BINARY, HEX, BUFFER};
+enum encoding {ASCII, UTF8, BASE64, UCS2, LATIN1, HEX, BUFFER, BINARY = LATIN1};
 NODE_EXTERN enum encoding ParseEncoding(
     v8::Isolate* isolate,
     v8::Local<v8::Value> encoding_v,

@trevnorris
Copy link
Contributor

@bnoordhuis I think that makes better sense. The two are functionally equivalent. Rest of the changes LGTM. (thanks for adding the native API tests)

The prerequisite for rebuilding was on the binding.gyp file but the
actual sources.

PR-URL: nodejs#7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
A missing 'break' statement unintentionally allowed "linary"
and "luffer" as alternatives for "binary" and "buffer".

Regression introduced in commit 54cc721 ("buffer: introduce latin1
encoding term".)

PR-URL: nodejs#7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
@bnoordhuis bnoordhuis closed this Jun 13, 2016
@bnoordhuis bnoordhuis deleted the linary-luffer branch June 13, 2016 10:56
@bnoordhuis bnoordhuis merged commit 6b48324 into nodejs:master Jun 13, 2016
@bnoordhuis
Copy link
Member Author

Landed in d06820c...6b48324, thanks. I'm going to follow up with a separate PR for the BINARY/LATIN1 thing.

@evanlucas
Copy link
Contributor

This depends on #7111 which is semver minor, so will hold out on this until the next v6.x minor release

evanlucas pushed a commit that referenced this pull request Jun 16, 2016
The prerequisite for rebuilding was on the binding.gyp file but the
actual sources.

PR-URL: #7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
@evanlucas evanlucas mentioned this pull request Jun 16, 2016
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Jun 19, 2016
Make BINARY an alias for LATIN1 rather than a distinct enum value.

PR-URL: nodejs#7284
Refs: nodejs#7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
@MylesBorins
Copy link
Contributor

added don't land label for v4.x

@evanlucas did you want to leave the v6.x label on there ?

@evanlucas
Copy link
Contributor

It actually depends on a semver-major change, so I believe that leaving the dont-land-on-v6.x is appropriate for now (unless something changes). Thanks!

addaleax pushed a commit to addaleax/node that referenced this pull request Aug 8, 2016
A missing 'break' statement unintentionally allowed "linary"
and "luffer" as alternatives for "binary" and "buffer".

Regression introduced in commit 54cc721 ("buffer: introduce latin1
encoding term".)

PR-URL: nodejs#7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
addaleax pushed a commit to addaleax/node that referenced this pull request Aug 8, 2016
Make BINARY an alias for LATIN1 rather than a distinct enum value.

PR-URL: nodejs#7284
Refs: nodejs#7262
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
@cjihrig cjihrig mentioned this pull request Aug 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants