Browse Source

fix: avoid using replaceAll

pull/2424/head
Wing-Kam Wong 2 years ago
parent
commit
4ff1137af5
  1. 6
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/sanitize.ts
  2. 8
      packages/nocodb/src/lib/models/Model.ts

6
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/sanitize.ts

@ -1,7 +1,9 @@
export function sanitize(v) {
return v?.replaceAll('?', '\\\\?');
return v?.replace(/([^\\]|^)(\?+)/g, (_, m1, m2) => {
return `${m1}${m2.split('?').join('\\?')}`;
});
}
export function unsanitize(v) {
return v?.replaceAll('\\?', '?');
return v?.replace(/\\[?]/g, '?');
}

8
packages/nocodb/src/lib/models/Model.ts

@ -404,7 +404,13 @@ export default class Model implements TableType {
for (const col of await this.getColumns()) {
if (isVirtualCol(col)) continue;
const val = data?.[col.column_name] ?? data?.[col.title];
insertObj[col.column_name.replaceAll('?', '\\\\?')] = val;
if (val !== undefined) {
insertObj[
col.column_name.replace(/([^\\]|^)(\?+)/g, (_, m1, m2) => {
return `${m1}${m2.split('?').join('\\?')}`;
})
] = val;
}
}
return insertObj;
}

Loading…
Cancel
Save