changeset 35731:75c63097b4d1

runtime(termdebug): quote filename arguments using double quotes Commit: https://github.com/vim/vim/commit/27f53346a303c5cf1bdfb8abca20e4fea8ec05e4 Author: Ubaldo Tiberi <ubaldo.tiberi@google.com> Date: Wed Jul 17 20:12:29 2024 +0200 runtime(termdebug): quote filename arguments using double quotes closes: https://github.com/vim/vim/issues/15270 Signed-off-by: Ubaldo Tiberi <ubaldo.tiberi@google.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Wed, 17 Jul 2024 20:30:04 +0200
parents ef648205e7c9
children c52ca620f43a
files runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -1325,6 +1325,11 @@ def DeleteCommands()
   sign_undefine(BreakpointSigns->map("'debugBreakpoint' .. v:val"))
 enddef
 
+def QuoteArg(x: string): string
+  # Find all the occurrences of " and \ and escape them and double quote
+  # the resulting string.
+  return printf('"%s"', x ->substitute('[\\"]', '\\&', 'g'))
+enddef
 
 # :Until - Execute until past a specified position or current line
 def Until(at: string)
@@ -1335,7 +1340,7 @@ def Until(at: string)
     ch_log('assume that program is running after this command')
 
     # Use the fname:lnum format
-    var AT = empty(at) ? $"\"{expand('%:p')}:{line('.')}\"" : at
+    var AT = empty(at) ? QuoteArg($"{expand('%:p')}:{line('.')}") : at
     SendCommand($'-exec-until {AT}')
   else
     ch_log('dropping command, program is running: exec-until')
@@ -1354,7 +1359,7 @@ def SetBreakpoint(at: string, tbreak=fal
   endif
 
   # Use the fname:lnum format, older gdb can't handle --source.
-  var AT = empty(at) ? $"\"{expand('%:p')}:{line('.')}\"" : at
+  var AT = empty(at) ? QuoteArg($"{expand('%:p')}:{line('.')}") : at
   var cmd = ''
   if tbreak
     cmd = $'-break-insert -t {AT}'