diff options
| author | Julian Andres Klode <jak@debian.org> | 2025-03-26 15:16:53 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2025-03-26 15:16:53 +0000 |
| commit | 823ff724d013dbe484e3da91bd54ae972f85629c (patch) | |
| tree | 0d8aaaba7123186aa1d5e32690a35b68498814da | |
| parent | 2a6c9bd8c0f8f50671bf7992f1e5d87b392e0336 (diff) | |
| parent | a452d3a9f526f6545981664712b45f709545e6fa (diff) | |
Merge branch 'fix-pager-env' into 'main'
Respect custom LESS/MORE/LV variables
See merge request apt-team/apt!468
| -rw-r--r-- | apt-private/private-output.cc | 12 | ||||
| -rwxr-xr-x | test/integration/test-apt-cli-pager | 3 |
2 files changed, 14 insertions, 1 deletions
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index 4480d7382..a1105be61 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -160,7 +160,17 @@ bool InitOutputPager() signal(sig, SIG_DFL); for (auto &v: pagerEnv) - putenv(v.data()); + { + // WARNING: VectorizeString() is not thread-safe, do not call after creating a thread. + auto keyAndValue = VectorizeString(v, '='); + if (keyAndValue.size() != 2) + { + _error->Fatal("Invalid environment string: %s", v.c_str()); + goto err; + } + // NOTE: Must not override user values, so setenv(..., override=0) is used rather than putenv() + setenv(keyAndValue[0].c_str(), keyAndValue[1].c_str(), 0); + } { // If our pager name contains a space we need to invoke it in a shell. Boooo! diff --git a/test/integration/test-apt-cli-pager b/test/integration/test-apt-cli-pager index d1f8c3288..cc220c81f 100755 --- a/test/integration/test-apt-cli-pager +++ b/test/integration/test-apt-cli-pager @@ -125,3 +125,6 @@ Checksums-Sha256: PAGER="head -2" testsuccessequal "Package: foo Binary: foo" runapt --unbuffer apt showsrc foo -o TestPager="head- 2" + +PAGER='echo $LESS' testsuccessequal "FRX" runapt --unbuffer apt showsrc foo -o TestPager='echo $LESS (1)' +LESS=FRXM PAGER='echo $LESS' testsuccessequal "FRXM" runapt --unbuffer apt showsrc foo -o TestPager='echo $LESS (2)' |
