Skip to content

Commit

Permalink
Merge pull request #895 from ychin/filename_sanitization_fixes
Browse files Browse the repository at this point in the history
Fix opening files that have special chars like '$' in filename
  • Loading branch information
ychin committed May 22, 2019
2 parents 651ad8e + 4ef03ed commit 2b77e8f
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 122 deletions.
29 changes: 9 additions & 20 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -976,21 +976,11 @@ - (BOOL)openFiles:(NSArray *)filenames withArguments:(NSDictionary *)args
//
// NOTE: Raise window before passing arguments, otherwise the
// selection will be lost when selectionRange is set.
firstFile = [firstFile stringByEscapingSpecialFilenameCharacters];

NSString *bufCmd = @"tab sb";
switch (layout) {
case MMLayoutHorizontalSplit: bufCmd = @"sb"; break;
case MMLayoutVerticalSplit: bufCmd = @"vert sb"; break;
case MMLayoutArglist: bufCmd = @"b"; break;
}

NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
":let oldswb=&swb|let &swb=\"useopen,usetab\"|"
"%@ %@|let &swb=oldswb|unl oldswb|"
"cal foreground()<CR>", bufCmd, firstFile];

[vc addVimInput:input];
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
firstFile, @"filename",
[NSNumber numberWithInt:layout], @"layout",
nil];
[vc sendMessage:SelectAndFocusOpenedFileMsgID data:[args dictionaryAsData]];
}

[vc passArguments:arguments];
Expand Down Expand Up @@ -1465,16 +1455,15 @@ - (void)newFileHere:(NSPasteboard *)pboard userData:(NSString *)userData
if (!dirIndicator)
path = [path stringByDeletingLastPathComponent];

path = [path stringByEscapingSpecialFilenameCharacters];

NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
BOOL openInCurrentWindow = [ud boolForKey:MMOpenInCurrentWindowKey];
MMVimController *vc;

if (openInCurrentWindow && (vc = [self topmostVimController])) {
NSString *input = [NSString stringWithFormat:@"<C-\\><C-N>"
":tabe|cd %@<CR>", path];
[vc addVimInput:input];
NSDictionary *args = [NSDictionary dictionaryWithObjectsAndKeys:
path, @"path",
nil];
[vc sendMessage:NewFileHereMsgID data:[args dictionaryAsData]];
} else {
[self launchVimProcessWithArguments:nil workingDirectory:path];
}
Expand Down
Loading

0 comments on commit 2b77e8f

Please sign in to comment.