autojump
autojump copied to clipboard
Crash on Windows due to improper backslash handling in autojump_match.py
Executing any normal autojump command in Windows leads to this:
Traceback (most recent call last):
File "C:\Program Files (x86)\CowShell\Vendor\AutoJump\bin\\autojump", line 320, in <module>
sys.exit(main(parse_arguments()))
File "C:\Program Files (x86)\CowShell\Vendor\AutoJump\bin\\autojump", line 314, in main
['.'])))
File "C:\Program Files (x86)\CowShell\Vendor\AutoJump\bin\autojump_utils.py", line 42, in first
return it.next()
File "C:\Program Files (x86)\CowShell\Vendor\AutoJump\bin\autojump_match.py", line 86, in <lambda>
flags=regex_flags,
File "F:\Programs\Python\lib\re.py", line 146, in search
return _compile(pattern, flags).search(string)
File "F:\Programs\Python\lib\re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: unexpected end of regular expression
ECHO is off.
The highlighted change here: https://github.com/wting/autojump/commit/7c7865ea7ecfd937284f774fb0818c5cc10c340a#diff-4b97c2fd2ae952c567c1646bc80e5d43L78 lead to the dysfunction in Windows systems.
The proposed solution is basically changing the lines 78-80 in autojump_match.py to:
sep = '\\\\' if os.sep == '\\' else os.sep
regex_no_sep = '[^' + sep + ']*'
regex_no_sep_end = regex_no_sep + '$'
regex_one_sep = regex_no_sep + sep + regex_no_sep
(Conditionally setting the separator value used in the regex construction)
Hey thanks for the detailed bug report!
Unfortunately I don't have access to a Windows machine. Can you update these Windows tests such that they reproduce the error you have? That way we can prevent future regression bugs.
Just trying out autojump on Win10 and hit this. The proposed patch seems to work for me.
@wting If the tests are not actually executed on Windows, won't the match_consecutive tests pick up the wrong os.sep
? The tests won't actually fail unless os.sep is a backslash.
You can mock it out for tests like so:
In [1]: import os, mock
In [2]: os.sep
Out[2]: '/'
In [3]: with mock.patch.object(os, 'sep', '\\'):
...: print(os.sep)
...:
\
I had the same problem and the suggested fix solved the problem. I guess that an alternative solution would be to run the tests on a windows CI platform such as appveyor.
win 10 64 , the same issue. change autojump_match.py worked. thank you.
Window 10 professional, I met this issue today....and the suggested patch works like a charm! Many thanks. I just wonder why the patch is not merged into the master while four years have been passed?
Window 11 professional, I met this issue today....and the suggested patch works like a charm! Many thanks. I just wonder why the patch is not merged into the master while four years have been passed?