Crash on Windows due to improper backslash handling in autojump_match.py
Created by: agorgl
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)