fix(mssql): avoid mutating input parameter array values (#11476)

* test(mssql): add test for unwanted mutation of input params

* fix(mssql): avoid mutating input parameter array values

* chore: add comment explaining input array test assertion
This commit is contained in:
Simon Garner 2025-05-14 21:41:07 +12:00 committed by GitHub
parent 9f889b3490
commit b8dbca515e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View File

@ -987,24 +987,17 @@ export class SqlServerDriver implements Driver {
*/
parametrizeValues(column: ColumnMetadata, value: any) {
if (value instanceof FindOperator) {
if (Array.isArray(value.value)) {
for (let i = 0; i < value.value.length; i++) {
value.value[i] = this.parametrizeValues(
column,
value.value[i],
)
}
} else if (value.type !== "raw") {
if (value.type !== "raw") {
value.transformValue({
to: (v) => this.parametrizeValue(column, v),
to: (v) => this.parametrizeValues(column, v),
from: (v) => v,
})
}
} else {
value = this.parametrizeValue(column, value)
return value
}
return value
return this.parametrizeValue(column, value)
}
/**

View File

@ -167,15 +167,21 @@ describe("github issues > #11285 Missing MSSQL input type", () => {
"query",
)
const excludedUserIds = [user2.memberId]
const users = await dataSource.getRepository(User).find({
where: {
memberId: And(Not(In([user2.memberId]))),
memberId: And(Not(In(excludedUserIds))),
},
})
expect(users).to.have.length(1)
expect(users[0].memberId).to.be.equal(user.memberId)
// Ensure that the input array was not mutated into MssqlParameter instances
// https://github.com/typeorm/typeorm/issues/11474
expect(excludedUserIds).to.eql([user2.memberId])
expect(selectSpy.calledOnce).to.be.true
sinon.assert.calledWithMatch(