From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY,URIBL_SBL_A autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22837 invoked from network); 2 Jun 2021 09:12:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jun 2021 09:12:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622625127; b=uh33q5eMa9NWTgYTepN6b43gvCtY6cms5dyE6X/T7DQHlGa9Z2WWdTNqpnWi02r8x5xe5D4fOR JQ83G27WNLqy24XrmjkwASxWam9ai6PlByvTnXuD/hb30X+PVcIQAFwCmtzn/7ArWFoQxX5YYV 3wkXWbF8ecU0arKseGO0CX6DWDkfKNJU+IMCKkSuUHPw+43e55zQRXk9nAoP7gSGog8IsDcOVE o9URV2+5Lbp+POMQVus9aZ8YzroZVqHFd0addqLcEdHp91kJWdGL9f4LkwqneEXpi0Qk4tRaC6 KSuAf3TnJ87mVWbTkEa67uVtA4vGiA0z7UBTQs3DT3eY4Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1622625127; bh=SgqJTkDIidi+cdtdh6/frNce/d1an65c8E69j4QwGts=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=KaUxdwOtEJNyTA78GiiVEgfxKOzYSM3cL85VZpfpUoFfNXRxL3vIaT7n/pAoHh/hodCkxU/liK mexyk4mEGiRzRjnzPfm/6LNt5dgqmMApCMgY6opqUXs6d2GhvlqkKlPSMwstczfVuhh/+qmx/l FiJmkY84Xz8AxBoqxN4ntYcf3qXSv0O6AC0cIc5ZUJpoIWlwbR2hjYcs01FXtE6gNyPSKDTVnu 8cQXbN572IfqlQAYBdlqDH1XBR2sfMz7vS8dElirjMrLGUi4fJzxIjwv5yUABnQsgD793l/j7d Dz6PyP9dePMzMEvmwsw+TQ20cihs9cUzZ7a5tgwqbD7T5Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=W3ajqEQ2FeZPOU9fG0euKPHn2YAucJHDluppHCAipEo=; b=DQLcqv+qx17kz0p/u5k+6B7e9H hNVgFCIz+ajcASMlZhXEYBlSNPRXqd9dSB+nd/10YtOiNJ/L8sBemA0zXCdVonIRErj2Dt0n3OJ7p fq0xn84P3AXTsNWKcg3j2dulXBGB1dX4ktRCUJ2KESW1zibFdAKELT+fNdfma7P7Z1MDzNOkrh/V8 IEYETYKpXZP+P3Ef8PHqR1x538bxF0vg+etXfW1IiFvzwolx6S+M2wAFOaiQYHPHRlBLw/iYVRjnI nihJc29oc69HQpS0P52LsxAe1Fx4R2z79B4ESkwJya18rmiC9oXJSM5TIJI6gzB+bZcdLzgUdR5e2 iNx6Fsrw==; Received: from authenticated user by zero.zsh.org with local id 1loMv0-00033d-DJ; Wed, 02 Jun 2021 09:12:06 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:60995) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1loMuh-0002mx-Vf; Wed, 02 Jun 2021 09:11:48 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 620ADFF80E; Wed, 2 Jun 2021 09:11:45 +0000 (UTC) Date: Wed, 2 Jun 2021 10:11:45 +0100 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [PATCH] (?) typeset array[position=index]=value Message-ID: <20210602091145.xvyymjxdors6kqya@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20191217111113.z242f4g6sx7xdwru@chaz.gmail.com> <2ea6feb3-a686-4d83-ab27-6a582424487c@www.fastmail.com> <20200101140343.qwfx2xaojumuds3d@chaz.gmail.com> <20210430061117.buyhdhky5crqjrf2@chazelas.org> <20210505114521.bemoiekpophssbug@chazelas.org> <20210601053235.b4junj6muuwegl7b@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 48983 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: 2021-06-01 09:05:13 -0700, Bart Schaefer: [...] > > [...] unless we're happy to break backward > > compatibility and make unset "assoc[$key]" work whatever the > > value of $key (unset 'assoc[f\]oo]]' for unset the element of > > key 'f\]oo]' for instance) > > Hm, I'm not sure what backward-compatibility would be broken? Do you > mean that scripts that already have work-arounds for the current issue > might stop working? Yes, like that guy's unset_keys at https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element/626529#626529 mentioned earlier. ATM, you need to do: unset 'hash[\]]' To unset the element of key "]" for instance. Having said that, in practice, it's rare for values to be passed literally. What you generally want to do is: unset "hash[$key]" With $key being any arbitrary string. And that's where the problem is. Maybe the best approach would be to make unset a dual keyword/builtin like typeset/export... so one can do: unset hash[$key] And that hash[$key] being interpreted the same as when you do: hash[$key]=value Being able to do: unset hash[(R)pattern] unset hash[(I)pattern] would also be useful. We don't want however subscript flags to be interpreted in: unset "hash[$key]" as that would introduce command injection vulnerabilities, like is already the case in things like: $ key='(n:evil:)' evil='psvar[$(uname>&2)1]' zsh -c 'typeset -A a; (( a[$key]++ ))' Linux Linux (though in that case, that's not limited to subscript flags, key='x]+psvar[$(uname>&2)1' works as well, see https://unix.stackexchange.com/questions/627474/how-to-use-associative-arrays-safely-inside-arithmetic-expressions/627475#627475 ) That's also why I was suggesting allowing: hash[$key]=() to unset an element, where you don't have the ambiguity of whether the contents of $key is going to be interpreted specially. -- Stephane