Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/strapi/node_modules/strapi-utils/lib/__tests__/ drwxr-xr-x | |
| Viewing file: Select action/file-type: const { escapeQuery, stringIncludes, stringEquals } = require('../string-formatting');
describe('string-formatting', () => {
describe('Escape Query', () => {
const testData = [
// [query, charsToEscape, escapeChar, expectedResult]
['123', '[%\\', '\\', '123'],
['12%3', '[%\\', '\\', '12\\%3'],
['1[2%3', '[%\\', '\\', '1\\[2\\%3'],
['1\\23', '[%\\', '\\', '1\\\\23'],
['123\\', '[%\\', '\\', '123\\\\'],
['\\', '[%\\', '\\', '\\\\'],
['123', '[%\\', '+', '123'],
['12%3', '[%\\', '+', '12+%3'],
['1[2%3', '[%\\', '+', '1+[2+%3'],
['1\\23', '[%\\', '+', '1+\\23'],
];
test.each(testData)(
'Escaping %s from %s with %s',
(query, charsToEscape, escapeChar, expectedResult) => {
const result = escapeQuery(query, charsToEscape, escapeChar);
expect(result).toEqual(expectedResult);
}
);
});
describe('stringIncludes', () => {
const tests = [
[['1', '2', '3'], '1', true],
[['1', '2', '3'], '4', false],
[[1, 2, 3], 1, true],
[[1, 2, 3], 4, false],
[[1, 2, 3], '1', true],
[[1, 2, 3], '4', false],
[[1, 2, 3], '01', false],
[['1', '2', '3'], 1, true],
[['1', '2', '3'], 4, false],
[['01', '02', '03'], 1, false],
];
test.each(tests)('%p includes %p : %p', (arr, val, expectedResult) => {
const result = stringIncludes(arr, val);
expect(result).toBe(expectedResult);
});
});
describe('stringEquals', () => {
const tests = [
['1', '1', true],
['1', '4', false],
[1, 1, true],
[1, 4, false],
[1, '1', true],
[1, '4', false],
[1, '01', false],
['1', 1, true],
['1', 4, false],
['01', 1, false],
];
test.each(tests)('%p includes %p : %p', (a, b, expectedResult) => {
const result = stringEquals(a, b);
expect(result).toBe(expectedResult);
});
});
});
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0048 ]-- |