Browse Source

fix: handle backslash in string literal

pull/7268/head
Pranav C 11 months ago
parent
commit
2da388f18c
  1. 8
      packages/nocodb/src/services/columns.service.ts
  2. 54
      packages/nocodb/tests/unit/rest/tests/formula.test.ts

8
packages/nocodb/src/services/columns.service.ts

@ -211,7 +211,7 @@ export class ColumnsService {
table.columns,
);
colBody.parsed_tree = await validateFormulaAndExtractTreeWithType({
formula: colBody.formula_raw || colBody.formula,
formula: colBody.formula || colBody.formula_raw,
columns: table.columns,
column,
clientOrSqlUi: source.type,
@ -1236,10 +1236,8 @@ export class ColumnsService {
colBody.parsed_tree = await validateFormulaAndExtractTreeWithType({
// formula may include double curly brackets in previous version
// convert to single curly bracket here for compatibility
formula:
colBody.formula_raw ||
colBody.formula?.replaceAll('{{', '{').replaceAll('}}', '}'),
column:{
formula: colBody.formula,
column: {
...colBody,
colOptions: colBody,
},

54
packages/nocodb/tests/unit/rest/tests/formula.test.ts

@ -64,37 +64,37 @@ function formulaRegExpBased() {
expect(unfilteredRecords.length).to.equal(100);
});
it('Type: REGEX_MATCH ', async () => {
it.only('Type: REGEX_MATCH ', async () => {
const formulaList = [
`REGEX_MATCH("123-45-6789", "\\\\d{3}-\\\\d{2}-\\\\d{4}")`,
'REGEX_MATCH("123-45-6789", "\\\\d{3}-\\\\d{2}-\\\\d{4}")',
'REGEX_MATCH("123-45-6789", "\\\\d{3}-\\\\d{2}-\\\\d{4}")',
'REGEX_MATCH("ABC-45-6789", "\\\\w{3}-\\\\d{2}-\\\\d{4}")',
'REGEX_MATCH("123-XY-6789", "\\\\d{3}-\\\\D{2}-\\\\d{4}")',
'REGEX_MATCH("123-45-$#@!", "123-45-[\\\\s\\\\S]{4}")',
`REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")`,
'REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("123-45-6789", "\\d{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("ABC-45-6789", "\\w{3}-\\d{2}-\\d{4}")',
'REGEX_MATCH("123-XY-6789", "\\d{3}-\\D{2}-\\d{4}")',
'REGEX_MATCH("123-45-$#@!", "123-45-[\\s\\S]{4}")',
'REGEX_MATCH("123456789", "1?2?3?-?4?5-?6?7?8?9?")',
'REGEX_MATCH("123-456789", "\\\\d{3}-?\\\\d{2}-?\\\\d{4}")',
'REGEX_MATCH("123-45-6789", "123-\\\\d{2}-6789")',
'REGEX_MATCH("abc123", "[a-z]{3}\\\\d{3}")',
'REGEX_MATCH("A1B2C3", "[A-Z]\\\\d[A-Z]\\\\d[A-Z]\\\\d")',
'REGEX_MATCH("hello123world", "\\\\w{5}\\\\d{3}\\\\w{5}")',
'REGEX_MATCH("email@example.com", "[a-zA-Z]+@[a-zA-Z]+\\\\.[a-zA-Z]+")',
'REGEX_MATCH("2023-12-14", "\\\\d{4}-\\\\d{2}-\\\\d{2}")',
'REGEX_MATCH("USD 100.50", "USD \\\\d+\\\\.\\\\d{2}")',
'REGEX_MATCH("http://www.example.com", "https?://[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}")',
'REGEX_MATCH("555-1234", "\\\\d{3}-\\\\d{4}")',
'REGEX_MATCH("username123", "[a-zA-Z]+\\\\d{3}")',
'REGEX_MATCH("apple, orange, banana", "\\\\w+, \\\\w+, \\\\w+")',
'REGEX_MATCH("aaaabbcc", "(\\\\w{2})\\\\1")',
'REGEX_MATCH("1234567890", "\\\\d{10}")',
'REGEX_MATCH("12.34", "\\\\d+\\\\.\\\\d{2}")',
'REGEX_MATCH("123 Main St, City", "\\\\d+ [a-zA-Z]+ St, [a-zA-Z]+")',
'REGEX_MATCH("X1Y2Z3", "[A-Z]\\\\d[A-Z]\\\\d[A-Z]\\\\d")',
'REGEX_MATCH("555-555-5555", "\\\\d{3}-\\\\d{3}-\\\\d{4}")',
'REGEX_MATCH("password123", "^(?=.*\\\\d)(?=.*[a-zA-Z]).{8,}$")',
'REGEX_MATCH("123-456789", "\\d{3}-?\\d{2}-?\\d{4}")',
'REGEX_MATCH("123-45-6789", "123-\\d{2}-6789")',
'REGEX_MATCH("abc123", "[a-z]{3}\\d{3}")',
'REGEX_MATCH("A1B2C3", "[A-Z]\\d[A-Z]\\d[A-Z]\\d")',
'REGEX_MATCH("hello123world", "\\w{5}\\d{3}\\w{5}")',
'REGEX_MATCH("email@example.com", "[a-zA-Z]+@[a-zA-Z]+\\.[a-zA-Z]+")',
'REGEX_MATCH("2023-12-14", "\\d{4}-\\d{2}-\\d{2}")',
'REGEX_MATCH("USD 100.50", "USD \\d+\\.\\d{2}")',
'REGEX_MATCH("http://www.example.com", "https?://[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}")',
'REGEX_MATCH("555-1234", "\\d{3}-\\d{4}")',
'REGEX_MATCH("username123", "[a-zA-Z]+\\d{3}")',
'REGEX_MATCH("apple, orange, banana", "\\w+, \\w+, \\w+")',
'REGEX_MATCH("aaaabbcc", "(\\w{2})\\1")',
'REGEX_MATCH("1234567890", "\\d{10}")',
'REGEX_MATCH("12.34", "\\d+\\.\\d{2}")',
'REGEX_MATCH("123 Main St, City", "\\d+ [a-zA-Z]+ St, [a-zA-Z]+")',
'REGEX_MATCH("X1Y2Z3", "[A-Z]\\d[A-Z]\\d[A-Z]\\d")',
'REGEX_MATCH("555-555-5555", "\\d{3}-\\d{3}-\\d{4}")',
'REGEX_MATCH("password123", "^(?=.*\\d)(?=.*[a-zA-Z]).{8,}$")',
'REGEX_MATCH("12345", "^[0-9]{5}$")',
'REGEX_MATCH("abc123!@#", "[a-zA-Z0-9!@#]+")',
'REGEX_MATCH("12-December-2023", "\\\\d{2}-[a-zA-Z]+-\\\\d{4}")',
'REGEX_MATCH("12-December-2023", "\\d{2}-[a-zA-Z]+-\\d{4}")',
];
for (let i = 0; i < formulaList.length; i++) {

Loading…
Cancel
Save