From 9001580c9bc0a0afb2874458b51ad566b9fefa20 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 Aug 2017 08:33:00 +0700 Subject: [PATCH] Do not expand env vars in parse_filename We have far enough ways to provide that feature, through the shell or through regular expands. Fixes #1545 --- src/file.cc | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/file.cc b/src/file.cc index 24db0c04..b7016672 100644 --- a/src/file.cc +++ b/src/file.cc @@ -48,32 +48,10 @@ public: String parse_filename(StringView filename) { - if (filename.length() >= 1 and filename[0_byte] == '~' and - (filename.length() == 1 or filename[1_byte] == '/')) - return parse_filename("$HOME" + filename.substr(1_byte)); - - ByteCount pos = 0; - String result; - for (ByteCount i = 0; i < filename.length(); ++i) - { - if (filename[i] == '$' and (i == 0 or filename[i-1] != '\\')) - { - result += filename.substr(pos, i - pos); - ByteCount end = i+1; - while (end != filename.length() and is_word(filename[end])) - ++end; - StringView var_name = filename.substr(i+1, end - i - 1); - const char* var_value = getenv(var_name.zstr()); - if (var_value) - result += var_value; - - pos = end; - } - } - if (pos != filename.length()) - result += filename.substr(pos); - - return result; + auto prefix = filename.substr(0_byte, 2_byte); + if (prefix == "~" or prefix == "~/") + return getenv("HOME") + filename.substr(1_byte); + return filename.str(); } std::pair split_path(StringView path)