fix(termopen): avoid ambiguity in URI when CWD is root dir (#16988)

This commit is contained in:
zeertzjq
2022-05-19 06:47:33 +08:00
committed by GitHub
parent 6f0baa0bb7
commit 18fbdaeeab
2 changed files with 49 additions and 1 deletions

View File

@@ -10790,10 +10790,16 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// "/home/foo/…" => "~/…"
size_t len = home_replace(NULL, NameBuff, IObuff, sizeof(IObuff), true);
// Trim slash.
if (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/') {
if (len != 1 && (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/')) {
IObuff[len - 1] = '\0';
}
if (len == 1 && IObuff[0] == '/') {
// Avoid ambiguity in the URI when CWD is root directory.
IObuff[1] = '.';
IObuff[2] = '\0';
}
// Terminal URI: "term://$CWD//$PID:$CMD"
snprintf((char *)NameBuff, sizeof(NameBuff), "term://%s//%d:%s",
(char *)IObuff, pid, cmd);