strapi/packages/strapi-utils/lib/__tests__/stringFormatting.test.js
Pierre Noël e0e561e6d0 add test for escapeQuery()
Signed-off-by: Pierre Noël <petersg83@gmail.com>
2020-04-30 19:47:04 +02:00

26 lines
796 B
JavaScript

const { escapeQuery } = require('../stringFormatting');
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);
}
);
});