diff --git a/news/fix-linecont.rst b/news/fix-linecont.rst new file mode 100644 index 000000000..e6630af3f --- /dev/null +++ b/news/fix-linecont.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed syntax error in scripts containing line continuation syntax. + +**Security:** + +* diff --git a/tests/test_integrations.py b/tests/test_integrations.py index 5c6d189ff..fb6117f49 100644 --- a/tests/test_integrations.py +++ b/tests/test_integrations.py @@ -289,10 +289,11 @@ def _echo(args): print(' '.join(args)) aliases['echo'] = _echo -echo --option1 \ +echo --option1 \\ --option2 -""", - "--option1 --option2\n", +echo missing \\ +EOL""", + "--option1 --option2\nmissing EOL\n", 0, ), # diff --git a/xonsh/execer.py b/xonsh/execer.py index b4daef78c..e9f07565a 100644 --- a/xonsh/execer.py +++ b/xonsh/execer.py @@ -242,6 +242,8 @@ class Execer(object): last_error_line = e.loc.lineno idx = last_error_line - 1 lines = input.splitlines() + if input.endswith("\n"): + lines.append("") line, nlogical, idx = get_logical_line(lines, idx) if nlogical > 1 and not logical_input: _, sbpline = self._parse_ctx_free( @@ -254,8 +256,6 @@ class Execer(object): last_error_col += 3 input = "\n".join(lines) continue - if input.endswith("\n"): - lines.append("") if len(line.strip()) == 0: # whitespace only lines are not valid syntax in Python's # interactive mode='single', who knew?! Just ignore them.