Use fnameescape to escape filepath
This commit is contained in:
parent
d99eb5d5cb
commit
c3859791ea
@ -47,6 +47,7 @@ MATCHADD_REGEX = re.compile(
|
||||
MATCHDELETE_REGEX = re.compile( '^matchdelete\((?P<id>\d+)\)$' )
|
||||
OMNIFUNC_REGEX_FORMAT = (
|
||||
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' )
|
||||
FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P<filepath>.+)\'\)$' )
|
||||
|
||||
# One-and only instance of mocked Vim object. The first 'import vim' that is
|
||||
# executed binds the vim module to the instance of MagicMock that is created,
|
||||
@ -211,6 +212,10 @@ def _MockVimEval( value ):
|
||||
if result is not None:
|
||||
return result
|
||||
|
||||
match = FNAMEESCAPE_REGEX.search( value )
|
||||
if match:
|
||||
return match.group( 'filepath' )
|
||||
|
||||
raise ValueError( 'Unexpected evaluation: {0}'.format( value ) )
|
||||
|
||||
|
||||
|
@ -1606,13 +1606,6 @@ def InsertNamespace_append_test( vim_current, *args ):
|
||||
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
||||
|
||||
|
||||
def EscapedFilepath_test():
|
||||
eq_( vimsupport.EscapedFilepath( '/path/ with /sp ac es' ),
|
||||
'/path/\ with\ /sp\ ac\ es' )
|
||||
eq_( vimsupport.EscapedFilepath( ' relative path/ with / spaces ' ),
|
||||
'\ relative\ path/\ with\ /\ spaces\ ' )
|
||||
|
||||
|
||||
@patch( 'ycmd.user_options_store._USER_OPTIONS',
|
||||
{ 'goto_buffer_command': 'same-buffer' } )
|
||||
@patch( 'vim.command', new_callable = ExtendedMock )
|
||||
|
@ -371,8 +371,9 @@ def BufferIsUsable( buffer_object ):
|
||||
return not BufferModified( buffer_object ) or HiddenEnabled( buffer_object )
|
||||
|
||||
|
||||
def EscapedFilepath( filepath ):
|
||||
return filepath.replace( ' ' , r'\ ' )
|
||||
def EscapeFilepathForVimCommand( filepath ):
|
||||
to_eval = "fnameescape('{0}')".format( EscapeForVim( filepath ) )
|
||||
return GetVariableValue( to_eval )
|
||||
|
||||
|
||||
# Both |line| and |column| need to be 1-based
|
||||
@ -422,8 +423,8 @@ def JumpToLocation( filename, line, column ):
|
||||
|
||||
vim_command = GetVimCommand( user_command )
|
||||
try:
|
||||
vim.command( 'keepjumps {0} {1}'.format( vim_command,
|
||||
EscapedFilepath( filename ) ) )
|
||||
escaped_filename = EscapeFilepathForVimCommand( filename )
|
||||
vim.command( 'keepjumps {0} {1}'.format( vim_command, escaped_filename ) )
|
||||
# When the file we are trying to jump to has a swap file
|
||||
# Vim opens swap-exists-choices dialog and throws vim.error with E325 error,
|
||||
# or KeyboardInterrupt after user selects one of the options.
|
||||
|
Loading…
Reference in New Issue
Block a user