From 5c994b0d474424057c7d36065c56e56066e0e0d4 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 18 Feb 2019 13:11:01 -0800 Subject: [PATCH 1/3] Only inherit a PWD if it resolves to "." Fixes #5647 --- CHANGELOG.md | 9 +++++++++ src/env.cpp | 13 +++++++------ tests/cd.in | 14 ++++++++++++++ tests/cd.out | 2 ++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a3a4771..590ab59dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# fish 3.0.2 + +This release of fish contains the following ixes: + +### Fixes and improvements + +- The PWD environment variable is now ignored if it does not resolve to the true working directory (#5647). + + # fish 3.0.1 (released February 11, 2019) This release of fish fixes a number of major issues discovered in fish 3.0.0. diff --git a/src/env.cpp b/src/env.cpp index 7c617cb2e..7d0b00679 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -960,12 +960,13 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { } } - // initialize the PWD variable if necessary - // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that. - // Note we treat PWD as read-only so it was not set in vars. - const char *incoming_pwd = getenv("PWD"); - if (incoming_pwd && incoming_pwd[0]) { - env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, str2wcstring(incoming_pwd)); + // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that + // if and only if it matches getcwd (#5647). Note we treat PWD as read-only so it was not set in + // vars. + const char *incoming_pwd_cstr = getenv("PWD"); + wcstring incoming_pwd = incoming_pwd_cstr ? str2wcstring(incoming_pwd_cstr) : wcstring{}; + if (!incoming_pwd.empty() && paths_are_same_file(incoming_pwd, L".")) { + env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, std::move(incoming_pwd)); } else { env_set_pwd_from_getcwd(); } diff --git a/tests/cd.in b/tests/cd.in index fde7cd558..e57124c17 100644 --- a/tests/cd.in +++ b/tests/cd.in @@ -46,8 +46,22 @@ mkdir -p $base/realhome set fish_path $PWD/../test/root/bin/fish ln -s $base/realhome $base/linkhome cd $base/linkhome +set -l real_getcwd (pwd -P) env HOME=$base/linkhome $fish_path -c 'echo PWD is $PWD' +# Do not inherit a virtual PWD that fails to resolve to getcwd (#5647) + +env HOME=$base/linkhome PWD=/tmp $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 1 succeeded" +or echo "BogusPWD test 1 failed: $output_pwd vs $real_getcwd" + +env HOME=$base/linkhome PWD=/path/to/nowhere $fish_path -c 'echo $PWD' | read output_pwd +test (realpath $output_pwd) = $real_getcwd +and echo "BogusPWD test 2 succeeded" +or echo "BogusPWD test 2 failed: $output_pwd vs $real_getcwd" + + # cd back before removing the test directory again. cd $oldpwd rm -Rf $base diff --git a/tests/cd.out b/tests/cd.out index 73081263d..8fd581f17 100644 --- a/tests/cd.out +++ b/tests/cd.out @@ -21,3 +21,5 @@ cd: #################### # Virtual PWD inheritance PWD is /tmp/cdcomp_test/linkhome +BogusPWD test 1 succeeded +BogusPWD test 2 succeeded From 6e24061468602f33e2d1db925f2cdeff3f782d10 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 19 Feb 2019 21:29:50 +0800 Subject: [PATCH 2/3] CHANGELOG: updates for 3.0.2 --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 590ab59dd..6f3f52cf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ # fish 3.0.2 -This release of fish contains the following ixes: +This release of fish fixes an issue discovered in fish 3.0.1. ### Fixes and improvements -- The PWD environment variable is now ignored if it does not resolve to the true working directory (#5647). +- The PWD environment variable is now ignored if it does not resolve to the true working directory, fixing strange behaviour in terminals started by editors and IDEs (#5647). +If you are upgrading from version 2.7.1 or before, please also review the release notes for 3.0.1, 3.0.0 and 3.0b1 (included below). + +--- # fish 3.0.1 (released February 11, 2019) From 28f57aa8ab6419205993dd440b30d130bf30c3f2 Mon Sep 17 00:00:00 2001 From: David Adam Date: Tue, 19 Feb 2019 21:33:05 +0800 Subject: [PATCH 3/3] Bump version for 3.0.2 --- CHANGELOG.md | 2 +- osx/Info.plist | 2 +- osx/config.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3f52cf2..debaef037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# fish 3.0.2 +# fish 3.0.2 (released February 19, 2019) This release of fish fixes an issue discovered in fish 3.0.1. diff --git a/osx/Info.plist b/osx/Info.plist index 10b7d27df..7415edb86 100644 --- a/osx/Info.plist +++ b/osx/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.0.1 + 3.0.2 CFBundleVersion 0.1 LSApplicationCategoryType diff --git a/osx/config.h b/osx/config.h index 77128ac1e..1828562e4 100644 --- a/osx/config.h +++ b/osx/config.h @@ -209,7 +209,7 @@ #define PACKAGE_NAME "fish" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "fish 3.0.1" +#define PACKAGE_STRING "fish 3.0.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "fish" @@ -218,7 +218,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.0.1" +#define PACKAGE_VERSION "3.0.2" /* The size of `wchar_t', as computed by sizeof. */ #define SIZEOF_WCHAR_T 4