From b632f62678a140d094c9a956d29fb50951a28e33 Mon Sep 17 00:00:00 2001 From: Ziv Date: Tue, 11 May 2021 13:35:45 +0800 Subject: [PATCH] fix: clea sql white spaces \n fix #21 (#26) --- src/utils/index.ts | 2 +- test/utils/index.test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index f869013..44952a2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -163,7 +163,7 @@ function splitSql(sql: string) { * @param {String} sql */ function cleanSql(sql: string) { - sql.trim(); // 删除前后空格 + sql = sql.trim(); // 删除前后空格 const tokens = lexer(sql); let resultSql = ''; let startIndex = 0; diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 1215835..3b69ff6 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -39,4 +39,12 @@ describe('utils', () => { const result = cleanSql(sql); expect(result.indexOf('xxx')).toEqual(-1); }); + + test('clean SQL white spaces', () => { + const sql = ` + select * from a; `; + const expected = 'select * from a;'; + const result = cleanSql(sql); + expect(result).toEqual(expected); + }); });