Skip to content

Commit

Permalink
preserve newlines in the middle
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Mar 23, 2023
1 parent 724cfa9 commit 2e3b6c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ export function cleanSqlComments(sql) {
// it sanitizes the following comment block groups
// group 1 -> /* */
// group 2 -> --
return sql
.replace(/--.*?$|\/\/.*?$|\/\*[\s\S]*?\*\/|(\n\s*)+/gm, '$1')
.trim();
return sql.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n').trim();
}

export function runQuery(query) {
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('async actions', () => {
const makeRequest = () => {
const request = actions.runQuery({
...query,
sql: '/*\nSELECT * FROM\n */\nSELECT 213--, {{ds}}\n/*\n{{new_param1}}\n{{new_param2}}*/FROM table',
sql: '/*\nSELECT * FROM\n */\nSELECT 213--, {{ds}}\n/*\n{{new_param1}}\n{{new_param2}}*/\n\nFROM table',
});
return request(dispatch, () => initialState);
};
Expand All @@ -310,7 +310,7 @@ describe('async actions', () => {
expect(fetchMock.calls(runQueryEndpoint)).toHaveLength(1);
expect(
JSON.parse(fetchMock.calls(runQueryEndpoint)[0][1].body).sql,
).toEqual('SELECT 213\nFROM table');
).toEqual('SELECT 213\n\n\nFROM table');
});
});
});
Expand Down

0 comments on commit 2e3b6c5

Please sign in to comment.