Commit 4ef03ed
committed
Fix opening files that have special chars like '$' in filename
This fixes a whole host of related issues in MacVim that fails to
properly sanitize filenames when opening files using the GUI (e.g.
drag-and-drop, file type associations, etc). The core issue came from
the fact that the code used to rely on constructing Vimscript commands
to send to code Vim to parse using `addInput` (e.g. `:tabe <filename>`).
This was convenient and fast to add new feature but requires properly
sanitizing filenames (since that's an arbitrary user input). It used a
bespoke function `stringByEscapingSpecialFilenameCharacters` but it
didn't fully work ('$' would not be escaped so it would be interpreted
as a Vim variable) for all filenames.
One solution should be to use Vim's fnameescape() utility, but it
doesn't fully solve all edge cases. For example, if we hae a newline in
a filename (which is admittedly weird) it will still break the Vimscript
parsing.
Better solution is to simply construct the raw Ex commands in C
manually. It forces more tie-in to Vim's internals but is the most
robust way to arbitary filenames. Replace all usage of
stringByEscapingSpecialFilenameCharacters with this method:
* `handleOpenWithArguments:` is used by drag-and-drop and opening files
from GUI, so fix that to construct Vim function calls. Also fixes some
weird bugs in existing behavior (e.g. if you drag multiple files in but
one of them is opened alrady, it used to choose the wrong tab to do the
`sall` split in. Now just make sure to make a new tab).
* Dragging files to tab bars. MacVim has a special behavior where
dragging files to tab bars will open files in that particular tab.
Consolidate the behavior to use `handleOpenWithArguments` as well. Also
fix an issue where previously it would forcefully stomp whatever buffer
you had in that tab even if it had unsaved changes.
* Misc cases: New File Here macOS service and a "open first file if
exists already" functionality also need to be fixed. For these two
cases, make new MMBackend handlers just for simplicity as they aren't
doing anything complicated.
For future TODO:
- Implement tests for this when new testing infrastructure is up for
testing MacVim-specific functionality.
Fix #863.1 parent 651ad8e commit 4ef03ed
7 files changed
Lines changed: 399 additions & 122 deletions
File tree
- src
- MacVim
- proto
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
976 | 976 | | |
977 | 977 | | |
978 | 978 | | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
994 | 984 | | |
995 | 985 | | |
996 | 986 | | |
| |||
1465 | 1455 | | |
1466 | 1456 | | |
1467 | 1457 | | |
1468 | | - | |
1469 | | - | |
1470 | 1458 | | |
1471 | 1459 | | |
1472 | 1460 | | |
1473 | 1461 | | |
1474 | 1462 | | |
1475 | | - | |
1476 | | - | |
1477 | | - | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
1478 | 1467 | | |
1479 | 1468 | | |
1480 | 1469 | | |
| |||
0 commit comments