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

mergeObject, Object.keys error in IE11 #117

Closed
volosovich opened this issue Sep 6, 2018 · 6 comments
Closed

mergeObject, Object.keys error in IE11 #117

volosovich opened this issue Sep 6, 2018 · 6 comments

Comments

@volosovich
Copy link

Hello guys,
I found next bug. We have the next function:

function mergeObject(target, source, options) {
	var destination = {}
	if (options.isMergeableObject(target)) {
		Object.keys(target).forEach(function(key) {
			destination[key] = cloneUnlessOtherwiseSpecified(target[key], options)
		})
	}
	Object.keys(source).forEach(function(key) {
		if (!options.isMergeableObject(source[key]) || !target[key]) {
			destination[key] = cloneUnlessOtherwiseSpecified(source[key], options)
		} else {
			destination[key] = deepmerge(target[key], source[key], options)
		}
	})
	return destination
}

I can send any value in source argument.
When I send number, string, boolean in Google Chrome and even Edge returns empty array.
But IE11 - throw exception.
I think need to check type of source before use Object.keys

@volosovich
Copy link
Author

volosovich commented Sep 6, 2018

this problem is indirectly related to #54

@TehShrike
Copy link
Owner

deepmerge only supports actual objects as arguments, not strings or numbers or booleans.

It doesn't specifically check what you pass in, but it doesn't explicitly support other uses either.

#54 is a discussion about whether or not undefined or null should be explicitly handled.

@volosovich
Copy link
Author

I agree with you, but all major browsers correct resolve this problem, except IE11. So a lot of developers can send the wrong argument and don't catch any problem. We have different behavior for different browsers, it's not good.
For my pov - if you think that argument should be only the Object, need to implement validator for that. Because a lot of people doesn't think about what they sent in source argument, and all work fine. Only if they catch an error in IE they start checking and spent some time for that.
And my last pov. For my opinion, in this case, need to do as for undefined value. When you send not Object - throw an error.
Thanks for lib, you do good job.

@volosovich
Copy link
Author

I can prepare PR if you this that validator it's a good idea.

@TehShrike
Copy link
Owner

I'd rather not add type-checking assertions to this smallish codebase - beyond adding a few more lines of code, it would be a breaking change, since there could be codebases passing in strings or whatever as the first argument, and it could be fine for them as long as they're not shipping to IE11.

I would rather focus on updating the typescript definition to be more correct/restrictive.

@TehShrike
Copy link
Owner

TypeScript types are published with deepmerge as of 2.2.0. #119

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

No branches or pull requests

2 participants