Auto merge of #2834 - micbou:fnameescape, r=micbou
[READY] Use fnameescape to escape filepath Spaces are not the only characters that need to be escaped when passing a filepath to a Vim command: `*`, `?`, `[`, `{`, etc. should be escaped too. Instead of escaping each one of these characters in Python, we use [the Vim function `fnameescape`](http://vimdoc.sourceforge.net/htmldoc/eval.html#fnameescape()). Closes #2623. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2834) <!-- Reviewable:end -->
This commit is contained in:
commit
cc4692bd42
@ -47,6 +47,7 @@ MATCHADD_REGEX = re.compile(
|
|||||||
MATCHDELETE_REGEX = re.compile( '^matchdelete\((?P<id>\d+)\)$' )
|
MATCHDELETE_REGEX = re.compile( '^matchdelete\((?P<id>\d+)\)$' )
|
||||||
OMNIFUNC_REGEX_FORMAT = (
|
OMNIFUNC_REGEX_FORMAT = (
|
||||||
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' )
|
'^{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
|
# 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,
|
# 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:
|
if result is not None:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
match = FNAMEESCAPE_REGEX.search( value )
|
||||||
|
if match:
|
||||||
|
return match.group( 'filepath' )
|
||||||
|
|
||||||
raise ValueError( 'Unexpected evaluation: {0}'.format( value ) )
|
raise ValueError( 'Unexpected evaluation: {0}'.format( value ) )
|
||||||
|
|
||||||
|
|
||||||
|
@ -1606,13 +1606,6 @@ def InsertNamespace_append_test( vim_current, *args ):
|
|||||||
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
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',
|
@patch( 'ycmd.user_options_store._USER_OPTIONS',
|
||||||
{ 'goto_buffer_command': 'same-buffer' } )
|
{ 'goto_buffer_command': 'same-buffer' } )
|
||||||
@patch( 'vim.command', new_callable = ExtendedMock )
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
||||||
|
@ -371,8 +371,9 @@ def BufferIsUsable( buffer_object ):
|
|||||||
return not BufferModified( buffer_object ) or HiddenEnabled( buffer_object )
|
return not BufferModified( buffer_object ) or HiddenEnabled( buffer_object )
|
||||||
|
|
||||||
|
|
||||||
def EscapedFilepath( filepath ):
|
def EscapeFilepathForVimCommand( filepath ):
|
||||||
return filepath.replace( ' ' , r'\ ' )
|
to_eval = "fnameescape('{0}')".format( EscapeForVim( filepath ) )
|
||||||
|
return GetVariableValue( to_eval )
|
||||||
|
|
||||||
|
|
||||||
# Both |line| and |column| need to be 1-based
|
# Both |line| and |column| need to be 1-based
|
||||||
@ -422,8 +423,8 @@ def JumpToLocation( filename, line, column ):
|
|||||||
|
|
||||||
vim_command = GetVimCommand( user_command )
|
vim_command = GetVimCommand( user_command )
|
||||||
try:
|
try:
|
||||||
vim.command( 'keepjumps {0} {1}'.format( vim_command,
|
escaped_filename = EscapeFilepathForVimCommand( filename )
|
||||||
EscapedFilepath( filename ) ) )
|
vim.command( 'keepjumps {0} {1}'.format( vim_command, escaped_filename ) )
|
||||||
# When the file we are trying to jump to has a swap file
|
# 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,
|
# Vim opens swap-exists-choices dialog and throws vim.error with E325 error,
|
||||||
# or KeyboardInterrupt after user selects one of the options.
|
# or KeyboardInterrupt after user selects one of the options.
|
||||||
|
Loading…
Reference in New Issue
Block a user