-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Clause): match whole variable when inlining using interpolate
Previously when inlining variables, a simple string replacement was used which meant that shorter variables could be inlined into longer ones. Eg. a variable "$param" could be inlined into the string "$paramName" to produce 'value'Name, which is obviously incorrect. The string replacement operation now attempts to only inline a param if it matches the entire variable.
- Loading branch information
Showing
2 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,28 @@ | ||
import { Clause } from './clause'; | ||
import { Where } from './clauses'; | ||
import { expect } from 'chai'; | ||
import { ParameterBag } from './parameter-bag'; | ||
|
||
describe('Clause', () => { | ||
describe('interpolate', () => { | ||
it('should correctly inline parameters that share a prefix', () => { | ||
class SpecialClause extends Clause { | ||
constructor(public query: string) { | ||
super(); | ||
} | ||
|
||
build() { | ||
return this.query; | ||
} | ||
} | ||
|
||
const bag = new ParameterBag(); | ||
bag.addParam('abc', 'param'); | ||
bag.addParam('def', 'paramLong'); | ||
|
||
const clause = new SpecialClause('param = $paramLong'); | ||
clause.useParameterBag(bag); | ||
expect(clause.interpolate()).to.equal(`param = 'def'`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters