[SERVER-61795] Incorrect Usage of Javascript Comparison to Compare Arrays and Objects Created: 30/Nov/21 Updated: 29/Oct/23 Resolved: 10/Feb/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 5.1.0-rc3 |
| Fix Version/s: | 5.3.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Mohammad Dashti (Inactive) | Assignee: | Justin Seyster |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | greenerbuild, neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Steps To Reproduce: | You can run the test like this:
You can change the expected result of any test done with testOpApprox in this file and all tests still pass. For example, you can replace:
with:
and the test-suite passes. |
| Participants: |
| Description |
|
The tests in expression_trigonometric.js use assert.lt (in here) to compare the array of results returned from the aggregation pipeline with an array created in JavaScript. Then, the implementation of assert.lt (in here) uses the < JavaScript operator to perform the less-than comparison. As JavaScript does not provide operator overloading, to perform the comparison between arrays or objects, calls toString on them and compares the results. For objects, toString always returns "[object Object]" for JavaScript-created objects and "[object BSON]" for BSON objects (usually returned from an aggregation pipeline). Then, the comparison here always returns true irrespective of the values, as long as a value exists. This is just one instance and we should keep an eye for other tests that might suffer from the same incorrect usage of JavaScript comparison operators.
|
| Comments |
| Comment by Githook User [ 07/Feb/22 ] |
|
Author: {'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}Message: |