zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: [PATCH] unmetafy $_ when exporting it to child
Date: Thu, 6 Apr 2023 15:22:13 +0900	[thread overview]
Message-ID: <6B8D9DF2-A8D4-4551-BA9D-55408342CF5B@kba.biglobe.ne.jp> (raw)

While testing my patch for the initialization of $_, I've noticed
that zsh exports _ to child without unmetafying pwd.

For example:

% mkdir -p /tmp/漢字 && cd /tmp/漢字
% echo $'#!/bin/ksh\necho $_' > foo
% chmod u+x foo
% ./foo | od -t c -t x1
0000000   /   t   m   p   / 346 274 203 202 345 255 203 267   /   .   /
         2f  74  6d  70  2f  e6  bc  83  82  e5  ad  83  b7  2f  2e  2f
0000020   f   o   o  \n
         66  6f  6f  0a
% echo 漢字 | od -t c -t x1
0000000 346 274 242 345 255 227  \n
         e6  bc  a2  e5  ad  97  0a

You can see that 'echo $_' outputs metafied value: a2 -> 83 82.

BTW, if we use ksh

% ksh
$ ./foo
./foo

So zsh exports _=/tmp/漢字/./foo, but ksh exports _=./foo.


diff --git a/Src/exec.c b/Src/exec.c
index 4328975b9..3b3d1235e 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -519,7 +519,7 @@ zexecve(char *pth, char **argv, char **newenvp)
     if (*pth == '/')
 	strcpy(buf + 2, pth);
     else
-	sprintf(buf + 2, "%s/%s", pwd, pth);
+	sprintf(buf + 2, "%s/%s", unmeta(pwd), pth);
     zputenv(buf);
 #ifndef FD_CLOEXEC
     closedumps();






                 reply	other threads:[~2023-04-06  6:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6B8D9DF2-A8D4-4551-BA9D-55408342CF5B@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).