mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Escape regex in path completion
This commit is contained in:
parent
3aa7c4769d
commit
cf973c202b
3 changed files with 31 additions and 0 deletions
14
news/escape_regex.rst
Normal file
14
news/escape_regex.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Escape regex characters in ``path_complete`` to avoid regex parsing errors for
|
||||
certain combinations of characters in path completer
|
||||
|
||||
**Security:** None
|
|
@ -1,5 +1,20 @@
|
|||
import pytest
|
||||
|
||||
from xonsh.environ import Env
|
||||
import xonsh.completers.path as xcp
|
||||
|
||||
|
||||
def test_pattern_need_quotes():
|
||||
# just make sure the regex compiles
|
||||
xcp.PATTERN_NEED_QUOTES.match('')
|
||||
|
||||
|
||||
def test_complete_path(xonsh_builtins):
|
||||
xonsh_builtins.__xonsh_env__ = {'CASE_SENSITIVE_COMPLETIONS': False,
|
||||
'GLOB_SORTED': True,
|
||||
'SUBSEQUENCE_PATH_COMPLETION': False,
|
||||
'FUZZY_PATH_COMPLETION': False,
|
||||
'SUGGEST_THRESHOLD': 3,
|
||||
'CDPATH': set(),
|
||||
}
|
||||
xcp.complete_path('[1-0.1]', '[1-0.1]', 0, 7, dict())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
import ast
|
||||
import glob
|
||||
import builtins
|
||||
|
||||
import xonsh.tools as xt
|
||||
|
@ -264,6 +265,7 @@ def complete_path(prefix, line, start, end, ctx, cdpath=True, filtfunc=None):
|
|||
env = builtins.__xonsh_env__
|
||||
csc = env.get('CASE_SENSITIVE_COMPLETIONS')
|
||||
glob_sorted = env.get('GLOB_SORTED')
|
||||
prefix = glob.escape(prefix)
|
||||
for s in xt.iglobpath(prefix + '*', ignore_case=(not csc),
|
||||
sort_result=glob_sorted):
|
||||
paths.add(s)
|
||||
|
|
Loading…
Add table
Reference in a new issue