Skip to content

Commit

Permalink
HCK-7477 (#126)
Browse files Browse the repository at this point in the history
* HCK-7477: Update regex

* HCK-7477: Fix tests

* HCK-7477: update regex
  • Loading branch information
Nightlngale authored Aug 1, 2024
1 parent 07a61ec commit 785ab01
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions forward_engineering/helpers/applyToInstanceHelper.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
5 changes: 4 additions & 1 deletion forward_engineering/utils/escapeString.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 785ab01

Please sign in to comment.