Skip to content

Commit e533143

Browse files
HCK-14288: Escape comment only when it has special chars (#182)
* HCK-14275: generate SQL for view column comment * HCK-14288: Escape comment only when it has special chars * fix * fix
1 parent f5d89dd commit e533143

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

forward_engineering/alterScript/alterScriptFromDeltaHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ const getAlterViewScriptDtos = (collection, app) => {
207207
const modifyScriptsData = getItemProperties(viewsData?.modified);
208208

209209
const createViewsScriptDtos = getItemProperties(viewsData?.added)
210-
.map(view => ({ ...view, ..._.omit(view.role, 'properties') }))
210+
.map(view => ({ ...view, ...view.role }))
211211
.filter(view => view.compMod?.created)
212212
.map(getAddViewScriptDto(app));
213213

214214
const deleteViewsScriptDtos = getItemProperties(viewsData?.deleted)
215-
.map(view => ({ ...view, ..._.omit(view.role, 'properties') }))
215+
.map(view => ({ ...view, ...view.role }))
216216
.map(getDeleteViewScriptDto(app));
217217

218218
const modifyViewsScriptDtos = modifyScriptsData

forward_engineering/utils/general.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ const _ = require('lodash');
1111
const { AlterCollectionDto, AlterCollectionRoleDto } = require('../alterScript/types/AlterCollectionDto');
1212
const { ReservedWordsAsArray } = require('../enums/reservedWords');
1313

14-
const MUST_BE_ESCAPED = /[\t\n'\f\r]/gm;
14+
const MUST_BE_ESCAPED = /[\t\n'\\\f\r]/gm;
15+
const ESCAPE_MAP = {
16+
'\n': '\\n',
17+
'\t': '\\t',
18+
'\r': '\\r',
19+
'\f': '\\f',
20+
'\\': '\\\\',
21+
"'": "\\'",
22+
};
1523

1624
const getDbName = containerData => {
1725
return _.get(containerData, '[0].code') || _.get(containerData, '[0].name', '');
@@ -161,9 +169,12 @@ const getDbVersion = (dbVersion = '') => {
161169
return Number(_.get(version, [0], 0));
162170
};
163171

164-
const prepareComment = (comment = '') => comment.replace(MUST_BE_ESCAPED, character => `\\${character}`);
172+
const prepareComment = (comment = '') => comment.replaceAll(MUST_BE_ESCAPED, ch => ESCAPE_MAP[ch]);
165173

166-
const wrapComment = comment => `E'${prepareComment(JSON.stringify(comment)).slice(1, -1)}'`;
174+
const wrapComment = (comment = '') => {
175+
const shouldBeEscaped = MUST_BE_ESCAPED.test(comment);
176+
return shouldBeEscaped ? `E'${prepareComment(comment)}'` : `'${comment}'`;
177+
};
167178

168179
const getFunctionArguments = functionArguments => {
169180
return _.map(functionArguments, arg => {

0 commit comments

Comments
 (0)