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

log_controller_test_case: Fix deepEqual returning true for primitive types #533

Merged
merged 1 commit into from Apr 9, 2022

Conversation

jcpascual
Copy link
Contributor

This PR fixes deepEqual to return the correct value when comparing primitive types.

When comparing obj1 and obj2, deepEqual first performs a standard === check. If that fails, it then proceeds to do a "deep comparison" with each targets' properties. However, since Object.keys(obj) always returns an empty array for primitive types, this means that deepEqual will always return true when comparing primitives as there are no properties to compare. (For example, deepEqual(true, false) will result in true.)

To avoid this, we only perform the deep comparison if both targets are of type object. If they are not, we return false.

Fixes #532.

@radiantshaw
Copy link
Contributor

@dhh If this PR looks good to you, can we please fast-forward merging this? Cause I'll need this for the PR I'm working on for resolving #530.

Copy link
Member

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

Thank you @jcpascual and @radiantshaw!

This looks good to me, let's get it merged!

@marcoroth marcoroth merged commit 9c0fd71 into hotwired:main Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

deepEqual always returns true when comparing two booleans
3 participants