Skip to content

Commit 6162405

Browse files
committed
fix(protect): treat undefined plaintext same as null in encryptQuery
Handle undefined plaintext values consistently with null by returning early (data: null) before sending to FFI. Updates both single and batch encrypt-query operations to use `=== null || === undefined` checks.
1 parent c6797db commit 6162405

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/protect/src/ffi/operations/batch-encrypt-query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { assertValidNumericValue } from '../helpers/validation'
1515
import { encryptedToCompositeLiteral, encryptedToEscapedCompositeLiteral } from '../../helpers'
1616

1717
/**
18-
* Separates null values from non-null terms in the input array.
19-
* Returns a set of indices where values are null and an array of non-null terms with their original indices.
18+
* Separates null/undefined values from non-null terms in the input array.
19+
* Returns a set of indices where values are null/undefined and an array of non-null terms with their original indices.
2020
*/
2121
function filterNullTerms(
2222
terms: readonly ScalarQueryTerm[],
@@ -28,7 +28,7 @@ function filterNullTerms(
2828
const nonNullTerms: { term: ScalarQueryTerm; originalIndex: number }[] = []
2929

3030
terms.forEach((term, index) => {
31-
if (term.value === null) {
31+
if (term.value === null || term.value === undefined) {
3232
nullIndices.add(index)
3333
} else {
3434
nonNullTerms.push({ term, originalIndex: index })

packages/protect/src/ffi/operations/encrypt-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class EncryptQueryOperation extends ProtectOperation<Encrypted> {
3535
queryType: this.opts.queryType,
3636
})
3737

38-
if (this.plaintext === null) {
38+
if (this.plaintext === null || this.plaintext === undefined) {
3939
return { data: null }
4040
}
4141

@@ -93,7 +93,7 @@ export class EncryptQueryOperationWithLockContext extends ProtectOperation<Encry
9393
}
9494

9595
public async execute(): Promise<Result<Encrypted, ProtectError>> {
96-
if (this.plaintext === null) {
96+
if (this.plaintext === null || this.plaintext === undefined) {
9797
return { data: null }
9898
}
9999

0 commit comments

Comments
 (0)