Skip to content

Commit 2e3b6c5

Browse files
committed
preserve newlines in the middle
1 parent 724cfa9 commit 2e3b6c5

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

superset-frontend/src/SqlLab/actions/sqlLab.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,7 @@ export function cleanSqlComments(sql) {
336336
// it sanitizes the following comment block groups
337337
// group 1 -> /* */
338338
// group 2 -> --
339-
return sql
340-
.replace(/--.*?$|\/\/.*?$|\/\*[\s\S]*?\*\/|(\n\s*)+/gm, '$1')
341-
.trim();
339+
return sql.replace(/(--.*?$|\/\*[\s\S]*?\*\/)\n?/gm, '\n').trim();
342340
}
343341

344342
export function runQuery(query) {

superset-frontend/src/SqlLab/actions/sqlLab.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('async actions', () => {
296296
const makeRequest = () => {
297297
const request = actions.runQuery({
298298
...query,
299-
sql: '/*\nSELECT * FROM\n */\nSELECT 213--, {{ds}}\n/*\n{{new_param1}}\n{{new_param2}}*/FROM table',
299+
sql: '/*\nSELECT * FROM\n */\nSELECT 213--, {{ds}}\n/*\n{{new_param1}}\n{{new_param2}}*/\n\nFROM table',
300300
});
301301
return request(dispatch, () => initialState);
302302
};
@@ -310,7 +310,7 @@ describe('async actions', () => {
310310
expect(fetchMock.calls(runQueryEndpoint)).toHaveLength(1);
311311
expect(
312312
JSON.parse(fetchMock.calls(runQueryEndpoint)[0][1].body).sql,
313-
).toEqual('SELECT 213\nFROM table');
313+
).toEqual('SELECT 213\n\n\nFROM table');
314314
});
315315
});
316316
});

0 commit comments

Comments
 (0)