-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: Invalid bytes length calculation #11165
Comments
That’s mostly because your example string isn’t valid Base64, so For |
Don't you think, this two ways must return the same value? Even their names say that ( |
In general, I assume that |
Does this means, that one of approaches calculates wrong length? |
@achugaev93 Oh, I agree – this naming collision is pretty unfortunate. Node didn’t choose the
Fwiw, that’s true for valid input (at least for a strict interpretation of “valid”)… (And by the way: You can use
Maybe? Depends on what you mean by “wrong”, I guess. I find it pretty hard to tell what the “right” length of |
Umm… what are you trying to say? I do know what Base64 is 😄 |
@achugaev93 First, it's preferable to use JavaScript in test cases, since not everyone here knows or is interested in learning TypeScript. Second, your test case is far from minimal. If I understood your issue correctly, you could easily shorten it to a few lines. Regarding the return value of I agree that this behavior could be documented though. |
Ok, it seems that only |
Both return correct length given a valid base64-encoded string. For invalid strings, there's no "correct" length. |
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
The behavior is documented now: 271d50a |
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: nodejs#11238 Refs: nodejs#11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: nodejs#11238 Refs: nodejs#11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
PR-URL: #11238 Refs: #11165 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Reference node issue nodejs/node#11165
Node Version: v7.5.0
Platform: Windows 10 x64
It seems that
Buffer.byteLength()
method andbuffer.byteLength
returns different values forbase64
encoding. Maybe for some others too.Here is TypeScript class that works with encodings:
The text was updated successfully, but these errors were encountered: