Skip to content

Commit dd88cb3

Browse files
fix(wl-sdk): escape SQL LIKE wildcards in one pass (#3852)
fix(wl-sdk): escape LIKE wildcards in one pass Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
1 parent 7f4b1b9 commit dd88cb3

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

‎packages/wl-sdk/src/commons/escape.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe('escapeSqlLike', () => {
6464
expect(escapeSqlLike('100%')).toBe('100\\%');
6565
expect(escapeSqlLike('a_b')).toBe('a\\_b');
6666
expect(escapeSqlLike("o'_malley%")).toBe("o''\\_malley\\%");
67+
expect(escapeSqlLike('%_%')).toBe('\\%\\_\\%');
6768
});
6869

6970
it('passes plain text through unchanged', () => {

‎packages/wl-sdk/src/commons/escape.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function escapeSqlString(s: string): string {
3333
* a backslash. Mirrors `commons.EscapeLIKE`.
3434
*/
3535
export function escapeSqlLike(s: string): string {
36-
return escapeSqlString(s).replace(/%/g, '\\%').replace(/_/g, '\\_');
36+
return escapeSqlString(s).replace(/[%_]/g, wildcard => `\\${wildcard}`);
3737
}
3838

3939
/**

0 commit comments

Comments
 (0)