From 0ca81e7cecaee96ba3f7fb7f7fc4011699431bf8 Mon Sep 17 00:00:00 2001 From: Sidharth Kshatriya Date: Thu, 24 Jun 2021 13:53:32 +0530 Subject: [PATCH] Fix: Kakoune passed environment variables in shell invocations are repeated If a %sh{} script refers to any variables multiple times they are all multiply included in the environment. Example: if a %sh{} invocation refers to ${kak_buffile} 5 times, the environment will have "kak_buffile=..." repeated 5 times and so on. This repetition happens for each multiply used variable that is passed into the environment. The variable should, of course, be only passed into the environment once. This commit should fix this issue. --- src/shell_manager.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shell_manager.cc b/src/shell_manager.cc index b683ac55..ebd6af40 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -144,8 +144,9 @@ Vector generate_env(StringView cmdline, const Context& context, const Sh StringView name{match[2].first, match[2].second}; auto match_name = [&](const String& s) { - return s.substr(0_byte, name.length()) == name and - s.substr(name.length(), 1_byte) == "="; + // 4_byte because of the initial `kak_` prefix + return s.substr(4_byte, name.length()) == name and + s.substr(4_byte + name.length(), 1_byte) == "="; }; if (any_of(env, match_name)) continue;