Skip to content

Commit fa33717

Browse files
authored
Merge pull request #15176 from Automattic/vkarpov15/gh-15170
fix(schema): handle bitwise operators on Int32
2 parents 39886fb + 0728602 commit fa33717

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Diff for: lib/schema/bigint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ SchemaBigInt.prototype.castForQuery = function($conditional, val, context) {
209209
return handler.call(this, val);
210210
}
211211

212-
return this.applySetters(null, val, context);
212+
return this.applySetters(val, context);
213213
}
214214

215215
try {

Diff for: lib/schema/boolean.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ SchemaBoolean.prototype.castForQuery = function($conditional, val, context) {
253253
return handler.call(this, val);
254254
}
255255

256-
return this.applySetters(null, val, context);
256+
return this.applySetters(val, context);
257257
}
258258

259259
try {

Diff for: lib/schema/int32.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const CastError = require('../error/cast');
88
const SchemaType = require('../schemaType');
99
const castInt32 = require('../cast/int32');
10+
const handleBitwiseOperator = require('./operators/bitwise');
1011

1112
/**
1213
* Int32 SchemaType constructor.
@@ -200,7 +201,11 @@ SchemaInt32.$conditionalHandlers = {
200201
$gt: handleSingle,
201202
$gte: handleSingle,
202203
$lt: handleSingle,
203-
$lte: handleSingle
204+
$lte: handleSingle,
205+
$bitsAllClear: handleBitwiseOperator,
206+
$bitsAnyClear: handleBitwiseOperator,
207+
$bitsAllSet: handleBitwiseOperator,
208+
$bitsAnySet: handleBitwiseOperator
204209
};
205210

206211
/*!
@@ -228,7 +233,7 @@ SchemaInt32.prototype.castForQuery = function($conditional, val, context) {
228233
return handler.call(this, val);
229234
}
230235

231-
return this.applySetters(null, val, context);
236+
return this.applySetters(val, context);
232237
}
233238

234239
try {

Diff for: test/cast.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ describe('cast: ', function() {
123123
{ x: { $bitsAnyClear: Buffer.from([3]) } });
124124
});
125125

126+
it('with int32 (gh-15170)', function() {
127+
const schema = new Schema({ x: 'Int32' });
128+
assert.deepEqual(cast(schema, { x: { $bitsAnySet: 3 } }),
129+
{ x: { $bitsAnySet: 3 } });
130+
});
131+
126132
it('throws when invalid', function() {
127133
const schema = new Schema({ x: Number });
128134
assert.throws(function() {
@@ -250,4 +256,10 @@ describe('cast: ', function() {
250256
'state.fieldFoo': '44'
251257
});
252258
});
259+
260+
it('treats unknown operators as passthrough (gh-15170)', function() {
261+
const schema = new Schema({ x: Boolean });
262+
assert.deepEqual(cast(schema, { x: { $someConditional: 'true' } }),
263+
{ x: { $someConditional: true } });
264+
});
253265
});

0 commit comments

Comments
 (0)