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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3458 invoked from network); 7 Aug 2023 02:37:17 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Aug 2023 02:37:17 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1691375837; b=Vyfeze4tSnQnD4u5BKq8W4c5HT5F4BQMtTnq3n4Q5e/734/HOYMekcm+CIe7UlFg9u9fgR8IOJ DjpmvA1T04RoV6oESEjDUDpFGEdEyl52H8hoJrxp70S0fJclwjXWtLBNN2WNCShjSTuh1jIKYd HSF+FgZBu7Ppc2T0Ewo4mZ/bp9H7A57hAnlrpgTQ7aZJT2RxYXGdg+Z/oDut+U1IE9rW1mCINb QjpZ8JOXc71VMKPVdLJZWcveD+/8le6ytpyZNBpsNsbCNxO6EH2Z5gyoBon4CV3wm+M4TwmUaz c83c9wnUFUO9vLnrZzoxYLrdf1uBbzkjSQrVvvRdR4knzA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=brasslantern-com.20221208.gappssmtp.com header.s=20221208 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1691375837; bh=TZUA8147e2zXO5D4mjDKiHIdy8jLducwkTE4F+mUQXc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=FzBaUNAJmTc7Z83lwrHYSAT04Y6rcHosMkrNgzcqtlOa5IQUaHXB23EqJ2AvbPuLlonfjfZVgp vMJ6ytMpvovVbGuB+WMHhwZ296ieRlHIZSiq7oT7k4X3+6zWdHlKyegtSYPc5NjyNpcEtPyfWS l91DHuGhryr6+75l3QEjmpo00QJxdh/KvzsYPf08QX4xLky7c9s4Lj8EQCQSgpOyOqSeCFhxWP KBGc9oJQyN1gJ6qAZsu8iacf4B6yKr6lVzapHiH2AuAp6iqFuM+BFSRalM1VMPnqzGu6xW2373 43SgLD5qjrnjxCYDazDzvvW7gWM54v+XqIE+N87hhgqJlQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=b3CvqwGLd2c5GHf/BS3LG09Uz9RVzHWPfB67lTNVqfc=; b=L2sgsLj31FlRl5fatL4VrZcWWN 5BITefDqPG7Ypqo1BGd6vieAAe9tZ3+FD9aSBlfBlZRPT0mnYdqbG49Q+eqDNQw49d6+4VhKJpbRW CifHcc3rQj/9IQSfb82loYNHgJOIcliwIFJq/gzQ8e1GeUyl1s6HE4IRG1tvw9/idvnxA6Ovol0Cs 1LR7zXOnBHtgC1sbqSEOz6WyU/Pk8nJaMhPYKMWUqQlXiBvUJe0Yq6/QjKKT/MWDTbJ7fWrfIitEV 9+oJ1OxZJE6Ty0GjI6y8mtVjU5gJ/Btl7esnbUMc1bC+zP8qKyBGxWN3kUd9Xf30wepfVxtdIJQ0K Fp0WG0rQ==; Received: by zero.zsh.org with local id 1qSq7Q-000DTC-Pb; Mon, 07 Aug 2023 02:37:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f178.google.com) smtp.remote-ip=209.85.208.178; dkim=pass header.d=brasslantern-com.20221208.gappssmtp.com header.s=20221208 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lj1-f178.google.com ([209.85.208.178]:60858) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1qSq6u-000D9Z-MK; Mon, 07 Aug 2023 02:36:45 +0000 Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2b9fa64db41so62474991fa.1 for ; Sun, 06 Aug 2023 19:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20221208.gappssmtp.com; s=20221208; t=1691375803; x=1691980603; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=b3CvqwGLd2c5GHf/BS3LG09Uz9RVzHWPfB67lTNVqfc=; b=pJY7PqYg1Y/Wqh2EEC5h4hn5FGHY4lgVrDz7q6H6KHCdpC868WXwvT9Dj8Hi7wLt1e Ev41e/d8VCJ0U4zlG4MsAxFbm0AyyrKRz1FK+U9c4xqDXXTSn2O2/rdhm5L5a0wjZprl IRHpHoGuCQJINR+LsZySy7t/HBD8T9VrGQqhj0ig/+5ERCyoOT0RQ+YE2Knnx9pPUn/6 AeIYTU0CGtrY5FE6wpvGiuZNcU2fiLQkE5jbV33DYQd2LZhPvoayVzsY5oEwGxqwJ9E9 vTvke1eOAsH9utMYVg/lwbYUaozkyXroI00B4Sj0rxKDhjnXWz1uL+O7G4uSSPL/heA9 62RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691375803; x=1691980603; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b3CvqwGLd2c5GHf/BS3LG09Uz9RVzHWPfB67lTNVqfc=; b=NGE1N8isHWEWQIkpIxmPq4P2s/+SpMJdkjZapLVxQHdW3zhS5XevY9g3DrIBrjdn82 0kKAUEX+zqJBurFQ0/A8ulrzGI+DVM60WgDWfcSxcy/f3AhpP1+VtJSV3Fq7iXhsdc/v oMQRicMgTYzVtw6lEnCoqStvbJbHhl1i4n/DWTor5GXCm6Yjx4SM4V5gAxyHliHn+NX+ rbOvg4mqIfspqdyjjmwPhq8emDv0ihRc8PihewsFZ3Yh5+aqB5OZoUDlfE0UFXi+LuQO UL1wozgBpo9haLFaOfQaUkoOsgJ4lO5XbnTJL24KNIszOuFqNDt81OzjGHiVjANHHiRG Yegg== X-Gm-Message-State: AOJu0YygEA2Vv17F/OlTku02pJ247KXJrVD6ngCXKd6Kg+DrCc0Ot3rf s8tl+Wk9lMBx3CCVJ2wuWkVLA33Rbb0Jfjt66x+U7WGECV4v5t00KCY= X-Google-Smtp-Source: AGHT+IGOFJAM1Wpoxgj+QHaxStb0EbL1rmHlReUxX6L4YAn840lgkUWx3j7v5Iy5VOYVab7aolTLsuxGqlVWnsA3mXQ= X-Received: by 2002:a2e:9248:0:b0:2b9:575e:5298 with SMTP id v8-20020a2e9248000000b002b9575e5298mr4892664ljg.13.1691375803372; Sun, 06 Aug 2023 19:36:43 -0700 (PDT) MIME-Version: 1.0 References: <20221211175001.u7dqfrnnzylsbjan@chazelas.org> In-Reply-To: From: Bart Schaefer Date: Sun, 6 Aug 2023 19:36:32 -0700 Message-ID: Subject: Re: a='foo"'; echo ${a/foo"/"bar} outputs bar To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52029 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: Circling back to this ... On Mon, Dec 12, 2022 at 10:21=E2=80=AFPM Bart Schaefer wrote: > > On Sun, Dec 11, 2022 at 9:50 AM Stephane Chazelas = wrote: > > > > $ a=3D'foo"' > > $ echo ${a/foo"/"bar} > > bar > > > > Whether quotes should escape the "/" is not clearly documented, > > though the doc does tell us to use backslash for that. > > The whole expression only works because the quotes are balanced: > > % echo ${x/foo"/bar} > braceparam dquote> > > Clearly something a little wacky is going on here. With an increased understanding of lex.c gained by stepping through variations of ${|...} a thousand times, I think I have identified two possible ways to address this. > > However the fact that the first " is taken as being part of the > > pattern while the second one is removed doesn't make much sense. > > This is the fault of singsub() called from line 2670 of > compgetmatch(), which eventually calls remnulargs() via prefork(), > which deletes the Dnull representing the double-quote. This is only a > problem because an unbalanced quote was able to sneak through. One possible change is for the first quote to be taken as part of the pattern but the second quote to NOT be removed. This results in $ echo ${a/foo"/"bar} braceparam dquote> It's always been possible to do quoted substrings in the replacement rather than in the pattern, so this is consistent. But it also means that $ a=3D'foo"' $ x=3D bar $ echo ${a/foo"/"$x"} $ bar Something similar would have to be done with single quotes, because handling double quotes doesn't fix this oddity: % a=3D"foo'" % x=3Dbar % echo ${a/foo'/$'${x}y} $bary That is, the single quote after the slash is simply ignored in the replacement. That happens in 5.9, 5.8, and earlier. The second possible change is to report "bad substitution" for the original example. As mentioned in the previous post, > This was actually caught at paramsubst() line 3118: > haserr =3D parse_subst_string(s); > This returned haserr =3D=3D 1, but the only effect of that is that the > string is retokenized at line 3124. An option I haven't pursued so far is to allow double-quoted substrings to appear in the pattern. This would make some sense given that we allow parameter expansions in the pattern and can protect them with single quotes, but using single quotes in the pattern has other unexpected side-effects on the replacement: % echo ${a/'foo"'/"$x"y} "bar"y Incidentally, it's sort-of possible in 5.8 to use $'...' quoting in patterns, but the same odd stuff is going on there as well. Thoughts?