-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescapeSQL.test.ts
More file actions
43 lines (33 loc) · 1.2 KB
/
Copy pathescapeSQL.test.ts
File metadata and controls
43 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export {};
import { escapeLikePattern } from '../../server/src/utils/escapeSQL';
describe('escapeLikePattern', () => {
test('returns empty string for null', () => {
expect(escapeLikePattern(null)).toBe('');
});
test('returns empty string for undefined', () => {
expect(escapeLikePattern(undefined)).toBe('');
});
test('returns empty string for non-string input', () => {
expect(escapeLikePattern(42)).toBe('');
expect(escapeLikePattern({})).toBe('');
});
test('returns empty string for empty string', () => {
expect(escapeLikePattern('')).toBe('');
});
test('escapes percent sign', () => {
expect(escapeLikePattern('test%')).toBe('test\\%');
});
test('escapes underscore', () => {
expect(escapeLikePattern('a_b')).toBe('a\\_b');
});
test('escapes backslash first to avoid double-escaping', () => {
expect(escapeLikePattern('a\\b')).toBe('a\\\\b');
});
test('escapes multiple special characters', () => {
expect(escapeLikePattern('a_b%c')).toBe('a\\_b\\%c');
});
test('leaves plain strings unchanged', () => {
expect(escapeLikePattern('Starbucks')).toBe('Starbucks');
expect(escapeLikePattern('Café WiFi')).toBe('Café WiFi');
});
});