diff --git a/packages/core/modules/config/index.js b/packages/core/modules/config/index.js index 90abff35c..10702c8a5 100644 --- a/packages/core/modules/config/index.js +++ b/packages/core/modules/config/index.js @@ -169,21 +169,21 @@ const operators = { reversedOp: "not_like", sqlOp: "LIKE", // tip: this function covers import of 3 operators - sqlImport: (sqlObj) => { + sqlImport: function (sqlObj) { if (sqlObj?.operator == "LIKE" || sqlObj?.operator == "NOT LIKE") { const not = sqlObj?.operator == "NOT LIKE"; const [_left, right] = sqlObj.children || []; if (right?.valueType?.endsWith("_quote_string")) { if (right?.value.startsWith("%") && right?.value.endsWith("%")) { - right.value = right.value.substring(1, right.value.length - 1); + right.value = this.utils.SqlString.unescapeLike(right.value.substring(1, right.value.length - 1)); sqlObj.operator = not ? "not_like" : "like"; return sqlObj; } else if (right?.value.startsWith("%")) { - right.value = right.value.substring(1); + right.value = this.utils.SqlString.unescapeLike(right.value.substring(1)); sqlObj.operator = "ends_with"; return sqlObj; } else if (right?.value.endsWith("%")) { - right.value = right.value.substring(0, right.value.length - 1); + right.value = this.utils.SqlString.unescapeLike(right.value.substring(0, right.value.length - 1)); sqlObj.operator = "starts_with"; return sqlObj; } diff --git a/packages/core/modules/index.d.ts b/packages/core/modules/index.d.ts index a4447bd17..3b2f9a659 100644 --- a/packages/core/modules/index.d.ts +++ b/packages/core/modules/index.d.ts @@ -603,6 +603,7 @@ interface ExportUtils { trim(val?: string): string; escape(val?: string): string; escapeLike(val?: string, any_start?: boolean, any_end?: boolean): string; + unescapeLike(val?: string): string; }, stringifyForDisplay(val: any): string; /** diff --git a/packages/core/modules/utils/export.js b/packages/core/modules/utils/export.js index 45423b766..326de398a 100644 --- a/packages/core/modules/utils/export.js +++ b/packages/core/modules/utils/export.js @@ -9,6 +9,16 @@ SqlString.trim = (val) => { return val; }; +SqlString.unescapeLike = (val) => { + if (typeof val !== "string") { + return val; + } + let res = val; + // unescape % and _ + res = res.replace(/\\([%_])/g, "$1"); + return res; +}; + SqlString.escapeLike = (val, any_start = true, any_end = true) => { if (typeof val !== "string") { return val;