zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] POSIX_CD: disable stack entries
@ 2019-12-12 10:38 ` Martijn Dekker
  2019-12-12 10:50   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2019-12-12 10:38 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 782 bytes --]

Recognising directory stack entries for the 'cd' builtin is not 
compatible with POSIX, because cd'ing into directories with names like 
+123 or -4567 no longer works without prefixing './', even after '--'. 
In POSIX, only the '-' operand has such a special meaning. The attached 
patch disables directory stack entries for 'cd' if POSIX_CD is active.

This patch also changes the behaviour of the 'chdir' equivalent. For 
POSIX compliance, only 'cd' needs to be changed, as POSIX has no 
'chdir'. I could change the patch to only change 'cd', but it would 
involve slightly more code, and would make 'cd' and 'chdir' no longer 
exactly equivalent. If this is preferred, please let me know.

Thanks,

- M.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

[-- Attachment #2: POSIX_CD.patch --]
[-- Type: text/plain, Size: 1836 bytes --]

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 15d3e0cf4..415bce613 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -290,6 +290,8 @@ of the list shown by the tt(dirs) command, starting with zero.
 An argument of the form `tt(-)var(n)' counts from the right.
 If the tt(PUSHD_MINUS) option is set, the meanings of `tt(PLUS())'
 and `tt(-)' in this context are swapped.
+If the tt(POSIX_CD) option is set, this form of tt(cd) is not recognised
+and will be interpreted as the first form.
 
 If the tt(-q) (quiet) option is specified, the hook function tt(chpwd)
 and the functions in the array tt(chpwd_functions) are not called.
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 903c31134..88bb643d1 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -148,7 +148,8 @@ ifzman(zmanref(zshbuiltins))\
 ifnzman(noderef(Shell Builtin Commands)).
 If the option is set, the shell does not test for directories beneath
 the local directory (`tt(.)') until after all directories in tt(cdpath)
-have been tested.
+have been tested, and the tt(cd) and tt(chdir) commands do not recognise
+arguments of the form `{tt(PLUS())|tt(-)}var(n)' as directory stack entries.
 
 Also, if the option is set, the conditions under which the shell
 prints the new directory after changing to it are modified.  It is
diff --git a/Src/builtin.c b/Src/builtin.c
index bd7736d2c..7bf4281da 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -912,7 +912,7 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
 	char *end;
 
 	doprintdir++;
-	if (argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-')
+	if (!isset(POSIXCD) && argv[0][1] && (argv[0][0] == '+' || argv[0][0] == '-')
 	    && strspn(argv[0]+1, "0123456789") == strlen(argv[0]+1)) {
 	    dd = zstrtol(argv[0] + 1, &end, 10);
 	    if (*end == '\0') {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] POSIX_CD: disable stack entries
  2019-12-12 10:38 ` [PATCH] POSIX_CD: disable stack entries Martijn Dekker
@ 2019-12-12 10:50   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2019-12-12 10:50 UTC (permalink / raw)
  To: zsh-workers

On Thu, 2019-12-12 at 11:38 +0100, Martijn Dekker wrote:
> Recognising directory stack entries for the 'cd' builtin is not 
> compatible with POSIX, because cd'ing into directories with names like 
> +123 or -4567 no longer works without prefixing './', even after '--'. 
> In POSIX, only the '-' operand has such a special meaning. The attached 
> patch disables directory stack entries for 'cd' if POSIX_CD is active.
> 
> This patch also changes the behaviour of the 'chdir' equivalent. For 
> POSIX compliance, only 'cd' needs to be changed, as POSIX has no 
> 'chdir'. I could change the patch to only change 'cd', but it would 
> involve slightly more code, and would make 'cd' and 'chdir' no longer 
> exactly equivalent. If this is preferred, please let me know.

Thanks, that sounds perfectly reasonable and I've committed it.

The intention of the POSIX options is entirely in accord with your
own --- make this clean and simple, with minimal confusion
with the clever stuff the shell does the rest of the time.

pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-12 10:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20191212103905eucas1p2c9c79ee9488ab73b48db0de1ac11faf7@eucas1p2.samsung.com>
2019-12-12 10:38 ` [PATCH] POSIX_CD: disable stack entries Martijn Dekker
2019-12-12 10:50   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).