Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re.error: bad escape \e #401

Open
Melandel opened this issue Dec 23, 2019 · 5 comments
Open

re.error: bad escape \e #401

Melandel opened this issue Dec 23, 2019 · 5 comments
Labels
area: interactive Tasks related to interactive support bug
Milestone

Comments

@Melandel
Copy link

Melandel commented Dec 23, 2019

Hello,

I am using Windows 10 (version 19536.1000) and windows powershell 5.1. My database is in a docker container.

When writing \e in the prompt, I get the following error and get ejected from the database:

Traceback (most recent call last):
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\main.py", line 117, in <module>
    main()
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\main.py", line 110, in main
    run_cli_with(mssqlcli_options)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\main.py", line 55, in run_cli_with
    mssqlcli.run()
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\mssql_cli.py", line 433, in run
    text = self.handle_editor_command(text)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\mssql_cli.py", line 296, in handle_editor_command
    query = (special.get_editor_query(text) or
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\site-packages\mssqlcli\packages\special\commands.py", line 317, in get_editor_query
    pattern = re.compile(r'(^\\\e|\\\e$)')
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\re.py", line 234, in compile
    return _compile(pattern, flags)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\re.py", line 286, in _compile
    p = sre_compile.compile(pattern, flags)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 924, in parse
    p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 420, in _parse_sub
    not nested and not items))
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 810, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 420, in _parse_sub
    not nested and not items))
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 501, in _parse
    code = _escape(source, this, state)
  File "C:\Users\MTR\AppData\Local\Programs\Python\Python37\lib\sre_parse.py", line 402, in _escape
    raise source.error("bad escape %s" % escape, len(escape))
re.error: bad escape \e at position 4

I tried setting the $EDITOR and $env:EDITOR variables, but it did not change the visible outcome.

Am I doing it wrong ? Is there a way I can use an external editor with mssql-cli ?
Also, would the external editor benefit from the autocompletion capabilities of mssql-cli ?

@Melandel
Copy link
Author

Bump!

@ellbosch
Copy link
Collaborator

ellbosch commented Jan 3, 2020

Sorry for the delay @Melandel—most of us took time off for the holidays. Thanks for bringing this to light, I have validated that this bug also occurs on Mac.

@ellbosch ellbosch added area: interactive Tasks related to interactive support bug labels Jan 3, 2020
@ellbosch ellbosch added this to the Backlog milestone Jan 3, 2020
@chrisg123
Copy link

This seems to have solved the issue for me.

diff --git a/mssqlcli/packages/special/commands.py b/mssqlcli/packages/special/commands.py
index d211242..f89eb3e 100644
--- a/mssqlcli/packages/special/commands.py
+++ b/mssqlcli/packages/special/commands.py
@@ -314,7 +314,7 @@ def get_editor_query(sql):
     # The reason we can't simply do .strip('\e') is that it strips characters,
     # not a substring. So it'll strip "e" in the end of the sql also!
     # Ex: "select * from style\e" -> "select * from styl".
-    pattern = re.compile(r'(^\\\e|\\\e$)')
+    pattern = re.compile(r'(^\\e|\\e$)')
     while pattern.search(sql):
         sql = pattern.sub('', sql)

Happy to submit a pull request if this is acceptable.

@yualan
Copy link
Collaborator

yualan commented May 19, 2020

Submitting a PR for this works for me :) @pensivebrian as fyi

chrisg123 added a commit to chrisg123/mssql-cli that referenced this issue May 19, 2020
@ljurk
Copy link

ljurk commented Feb 22, 2021

Hey, any updates on this issue/PR? I can confirm that the changes in #479 solve the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: interactive Tasks related to interactive support bug
Projects
None yet
Development

No branches or pull requests

5 participants