diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index b3a7b9a5e5..8fac9a9ade 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -371,18 +371,38 @@ export class ColumnsService { ); if (colBody.cdf) { if (colBody.uidt === UITypes.SingleSelect) { - if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { - NcError.badRequest( - `Default value '${colBody.cdf}' is not a select option.`, - ); - } - } else { - for (const cdf of colBody.cdf.split(',')) { - if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + try { + if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { NcError.badRequest( - `Default value '${cdf}' is not a select option.`, + `Default value '${colBody.cdf}' is not a select option.`, ); } + } catch (e) { + colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); + if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${colBody.cdf}' is not a select option.`, + ); + } + } + } else { + try { + for (const cdf of colBody.cdf.split(',')) { + if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${cdf}' is not a select option.`, + ); + } + } + } catch (e) { + colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); + for (const cdf of colBody.cdf.split(',')) { + if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${cdf}' is not a select option.`, + ); + } + } } } @@ -1146,18 +1166,38 @@ export class ColumnsService { // Handle default values if (colBody.cdf) { if (colBody.uidt === UITypes.SingleSelect) { - if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { - NcError.badRequest( - `Default value '${colBody.cdf}' is not a select option.`, - ); - } - } else { - for (const cdf of colBody.cdf.split(',')) { - if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + try { + if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { NcError.badRequest( - `Default value '${cdf}' is not a select option.`, + `Default value '${colBody.cdf}' is not a select option.`, ); } + } catch (e) { + colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); + if (!optionTitles.includes(colBody.cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${colBody.cdf}' is not a select option.`, + ); + } + } + } else { + try { + for (const cdf of colBody.cdf.split(',')) { + if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${cdf}' is not a select option.`, + ); + } + } + } catch (e) { + colBody.cdf = colBody.cdf.replace(/^'/, '').replace(/'$/, ''); + for (const cdf of colBody.cdf.split(',')) { + if (!optionTitles.includes(cdf.replace(/'/g, "''"))) { + NcError.badRequest( + `Default value '${cdf}' is not a select option.`, + ); + } + } } }