File tree Expand file tree Collapse file tree
forward_engineering/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,15 @@ const _ = require('lodash');
1111const { AlterCollectionDto, AlterCollectionRoleDto } = require ( '../alterScript/types/AlterCollectionDto' ) ;
1212const { 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
1624const 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
168179const getFunctionArguments = functionArguments => {
169180 return _ . map ( functionArguments , arg => {
You can’t perform that action at this time.
0 commit comments