Skip to content

Add check for Buffer#11

Closed
mikaelkaron wants to merge 1 commit intofastify:masterfrom
mikaelkaron:patch-1
Closed

Add check for Buffer#11
mikaelkaron wants to merge 1 commit intofastify:masterfrom
mikaelkaron:patch-1

Conversation

@mikaelkaron
Copy link

closes #10

Checklist

@mikaelkaron mikaelkaron marked this pull request as draft September 21, 2022 19:11
@mikaelkaron mikaelkaron changed the title wip: Add check for Buffer Add check for Buffer Sep 21, 2022
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Thanks for opening a PR! Can you please add a unit test?

@mikaelkaron
Copy link
Author

For sure. I was planning on doing that anyways, just made a draft to know if you are ok with the solution.

@Uzlopak
Copy link
Contributor

Uzlopak commented Sep 23, 2022

The issue with this PR is, that it is a breaking change. Also it would mean that it would probably not work in Browser because Browser does not have a builtin Buffer. So a instanceof Buffer would throw.

Also i can not agree with the assessment, that Array.isArray(Buffer.from([])) or Buffer.from([]) is returning true. So the Array Merge logic does not get applied. I assume It happens only if there is a buffer polyfill existing which is using Array as parent class.

@mikaelkaron
Copy link
Author

The issue with this PR is, that it is a breaking change. Also it would mean that it would probably not work in Browser because Browser does not have a builtin Buffer. So a instanceof Buffer would throw.

This is true.

Also i can not agree with the assessment, that Array.isArray(Buffer.from([])) or Buffer.from([]) is returning true. So the Array Merge logic does not get applied. I assume It happens only if there is a buffer polyfill existing which is using Array as parent class.

I was to quick on my assessment there, the array merge logic does indeed not get applied. I'll try to rework the MR to manage these two points.


function isMergeableObject (value) {
return typeof value === 'object' && value !== null && !(value instanceof RegExp) && !(value instanceof Date)
return typeof value === 'object' && value !== null && !(value instanceof RegExp) && !(value instanceof Date) && !(value instanceof Buffer)
Copy link
Member

Choose a reason for hiding this comment

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

I think we have the same issue with Stream objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer is merged like Array

4 participants