Преглед изворни кода

Refs #3836. Fixed null compared to null bug in Value.compare

Spencer Rathbun пре 12 година
родитељ
комит
4a87b43632
2 измењених фајлова са 24 додато и 2 уклоњено
  1. 3 2
      lib/pipeline/Value.js
  2. 21 0
      test/lib/aggregate.js

+ 3 - 2
lib/pipeline/Value.js

@@ -140,8 +140,9 @@ klass.cmp = function cmp(l, r){
  **/
  **/
 var Document;  // loaded lazily below //TODO: a dirty hack; need to investigate and clean up
 var Document;  // loaded lazily below //TODO: a dirty hack; need to investigate and clean up
 klass.compare = function compare(l, r) {
 klass.compare = function compare(l, r) {
-	var lt = typeof(l),
-		rt = typeof(r),
+	//NOTE: deviation from mongo code: we have to do some coercing for null "types" because of javascript
+	var lt = l === null ? "null" : typeof(l),
+		rt = r === null ? "null" : typeof(r),
 		ret;
 		ret;
 
 
 	// NOTE: deviation from mongo code: javascript types do not work quite the same, so for proper results we always canonicalize, and we don't need the "speed" hack
 	// NOTE: deviation from mongo code: javascript types do not work quite the same, so for proper results we always canonicalize, and we don't need the "speed" hack

+ 21 - 0
test/lib/aggregate.js

@@ -245,6 +245,27 @@ module.exports = {
 			});
 			});
 		}
 		}
 
 
+		"should be able to successfully compare a null to a null": function(next){
+			testAggregate({
+				inputs: [
+					{
+						cond:null,
+						value:"Authorized"
+					}
+				],
+				pipeline: [
+					{$project:{
+						retValue:{$cond:[
+							{$eq:["$cond", null]},
+							"$value",
+							null
+						]}
+					}}
+				],
+				expected: [{"retValue":"Authorized"}],
+				next: next
+			});
+		},
 	}
 	}
 
 
 };
 };