From 785ab01b4cbb55ce5a9e6a061fac271fd8d9dc52 Mon Sep 17 00:00:00 2001 From: Yevhenii Moroziuk Date: Thu, 1 Aug 2024 14:19:10 +0300 Subject: [PATCH] HCK-7477 (#126) * HCK-7477: Update regex * HCK-7477: Fix tests * HCK-7477: update regex --- forward_engineering/helpers/applyToInstanceHelper.js | 3 +-- .../helpers/commentHelpers/commentDeactivatedHelper.js | 6 +----- .../helpers/commentHelpers/commentDropStatements.js | 1 - forward_engineering/utils/escapeString.js | 5 ++++- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/forward_engineering/helpers/applyToInstanceHelper.js b/forward_engineering/helpers/applyToInstanceHelper.js index 31732942..18c99430 100644 --- a/forward_engineering/helpers/applyToInstanceHelper.js +++ b/forward_engineering/helpers/applyToInstanceHelper.js @@ -1,9 +1,8 @@ const async = require('async'); -const { filterDeactivatedQuery, queryIsDeactivated } = require('./commentHelpers/commentDeactivatedHelper'); +const { queryIsDeactivated } = require('./commentHelpers/commentDeactivatedHelper'); const snowflakeHelper = require('../../reverse_engineering/helpers/snowflakeHelper'); const createQueries = (script = '') => { - script = filterDeactivatedQuery(script); return script .split(';') .filter(Boolean) diff --git a/forward_engineering/helpers/commentHelpers/commentDeactivatedHelper.js b/forward_engineering/helpers/commentHelpers/commentDeactivatedHelper.js index 304767f2..6d7cc5e8 100644 --- a/forward_engineering/helpers/commentHelpers/commentDeactivatedHelper.js +++ b/forward_engineering/helpers/commentHelpers/commentDeactivatedHelper.js @@ -1,7 +1,6 @@ const _ = require('lodash'); -const MULTILINE_COMMENT = /(\n\/\*\n[\s\S]*?\n\s\*\/\n)|(\n\/\*\n[\s\S]*?\n\s\*\/)$/gi; -const STARTS_QUERY = ['//', '--']; +const STARTS_QUERY = ['//']; const commentIfDeactivated = (statement, data, isPartOfLine) => { if (_.has(data, 'isActivated') && !data.isActivated) { @@ -22,12 +21,9 @@ const commentIfDeactivated = (statement, data, isPartOfLine) => { return statement; }; -const filterDeactivatedQuery = query => query.replace(MULTILINE_COMMENT, ''); - const queryIsDeactivated = (query = '') => STARTS_QUERY.some(startQuery => query.startsWith(startQuery)); module.exports = { commentIfDeactivated, - filterDeactivatedQuery, queryIsDeactivated, }; diff --git a/forward_engineering/helpers/commentHelpers/commentDropStatements.js b/forward_engineering/helpers/commentHelpers/commentDropStatements.js index efd133a4..947b45c6 100644 --- a/forward_engineering/helpers/commentHelpers/commentDropStatements.js +++ b/forward_engineering/helpers/commentHelpers/commentDropStatements.js @@ -3,7 +3,6 @@ const { DROP_STATEMENTS } = require('../constants'); const commentDropStatements = (script = '') => script .split('\n') - .filter(line => line.trim()) .map(line => { if (DROP_STATEMENTS.some(statement => line.includes(statement))) { return `// ${line}`; diff --git a/forward_engineering/utils/escapeString.js b/forward_engineering/utils/escapeString.js index 4dd3c4f2..0c620e65 100644 --- a/forward_engineering/utils/escapeString.js +++ b/forward_engineering/utils/escapeString.js @@ -1,7 +1,10 @@ const { FORMATS } = require('../helpers/constants'); +const MUST_BE_ESCAPED = + /(\\r|\\n|\\b|\\f|\\t|'|"|\\[0-9]{3}|\0|\\x5C[0-3]?[0-7]{1,2}|\x5C[xX][0-9A-Fa-f]{2}|\x5C[uU][0-9A-Fa-f]{4})/g; + const escapeString = (scriptFormat, value) => - scriptFormat === FORMATS.SNOWSIGHT ? `'${value.replace(/'/g, "''")}'` : `$$${value}$$`; + scriptFormat === FORMATS.SNOWSIGHT ? `'${value.replace(MUST_BE_ESCAPED, '\\$1')}'` : `$$${value}$$`; module.exports = { escapeString,