diff --git a/shell/ext-py/sqlparse-0.1.19/sqlparse/lexer.py b/shell/ext-py/sqlparse-0.1.19/sqlparse/lexer.py index fd29f5c77..a589e0ba6 100644 --- a/shell/ext-py/sqlparse-0.1.19/sqlparse/lexer.py +++ b/shell/ext-py/sqlparse-0.1.19/sqlparse/lexer.py @@ -196,7 +196,8 @@ class Lexer(object): (r'[-]?[0-9]+', tokens.Number.Integer), (r"'(''|\\\\|\\'|[^'])*'", tokens.String.Single), # not a real string literal in ANSI SQL: - (r'(""|".*?[^\\]")', tokens.String.Symbol), + # A patch based on: https://github.com/andialbrecht/sqlparse/pull/396 + (r'"(""|\\\\|\\"|[^"])*"', tokens.String.Symbol), # sqlite names can be escaped with [square brackets]. left bracket # cannot be preceded by word character or a right bracket -- # otherwise it's probably an array index diff --git a/shell/ext-py/sqlparse-0.1.19/tests/test_split.py b/shell/ext-py/sqlparse-0.1.19/tests/test_split.py index 54e8d04db..03eddea1f 100644 --- a/shell/ext-py/sqlparse-0.1.19/tests/test_split.py +++ b/shell/ext-py/sqlparse-0.1.19/tests/test_split.py @@ -136,6 +136,15 @@ class SQLSplitTest(TestCaseBase): stmts = list(sqlparse.parsestream(stream)) self.assertEqual(type(stmts[0].tokens[0].value), unicode) + def test_split_quotes_with_new_line(self): + stmts = sqlparse.split('select "foo\nbar"') + assert len(stmts) == 1 + assert stmts[0] == 'select "foo\nbar"' + + stmts = sqlparse.split("select 'foo\n\bar'") + assert len(stmts) == 1 + assert stmts[0] == "select 'foo\n\bar'" + def test_split_simple(): stmts = sqlparse.split('select * from foo; select * from bar;') diff --git a/tests/shell/test_shell_interactive.py b/tests/shell/test_shell_interactive.py index 4065f9ae1..f53ee5a7d 100755 --- a/tests/shell/test_shell_interactive.py +++ b/tests/shell/test_shell_interactive.py @@ -501,6 +501,20 @@ class TestImpalaShellInteractive(object): result = run_impala_shell_interactive(query) assert '| id |' in result.stdout + @pytest.mark.execute_serially + def test_fix_infinite_loop(self): + # IMPALA-6337: Fix infinite loop. + result = run_impala_shell_interactive("select 1 + 1; \"\n;\";") + assert '| 2 |' in result.stdout + result = run_impala_shell_interactive("select '1234'\";\n;\n\";") + assert '| 1234 |' in result.stdout + result = run_impala_shell_interactive("select 1 + 1; \"\n;\"\n;") + assert '| 2 |' in result.stdout + result = run_impala_shell_interactive("select '1\\'23\\'4'\";\n;\n\";") + assert '| 1\'23\'4 |' in result.stdout + result = run_impala_shell_interactive("select '1\"23\"4'\";\n;\n\";") + assert '| 1"23"4 |' in result.stdout + @pytest.mark.execute_serially def test_shell_prompt(self): proc = pexpect.spawn(SHELL_CMD)