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=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 1829 invoked from network); 13 Dec 2022 06:22:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Dec 2022 06:22:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1670912530; b=LjiPSkCxa9Vuf5BHcnhOANXdXdOW0PjkIdS6LXdT2Nnwo63/HWAK4aiC+TGf4MFMqEJCD94pS5 6/RUAcJ5t8AD9SJrW2m0oksKr2IKqIQWBll07taoz+HyQOHmhHskbnQgzUSlM7BxDhEick9gty yfC4NjWAaqD5/SqqCJ02OTFdySQHxCB0YP3WKVT05UvOsW3EQ8pk0LODpW4mzNn7Ue5RU5stSq FTIjq9cZ3SG2tLJv3conDIW2KXZRqpfVpQTJ6bjJcu0/90iYT4CrH8xuXTuMWm+u847ffRTIqw OE1k+bq5dLBRFWbVoa38IZZL1Jts5irhi+LAZ7zfW5dolw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f41.google.com) smtp.remote-ip=209.85.208.41; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1670912530; bh=mPhG6OzZp0fZzvp4NDFH1jrE0GcZpFy6Z9S0oQ9aCoA=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=C8qquwzcdmjYolWG80f9W11qZEkEeJ3x7GqLcfYg/ANJ2tSODSHmdbMy4D5BIa3mrYonmnlv6b tj1uqGRXKHAfCmxx5zB597rycXKktjEdaUEvFwmPz0GOlK5iS8+WQuDoSxxJc8m9lkmB7AaqT/ EQcbbsaSU83AENFY8D6oYFRgb8p41H3a3A6wBVJdQ8/KldrJaR9PhBPu3WJjYyS5+HsJlKvD8x vT7yh15MFtnMPukiNBN9/mJVW1oibJ4/qfgLLjn5E20MVIAtobPruUOECHyxqu5APL2tE2oYml TG12hL1F3DPVoYgntMIIe+P2aockB3GT2w9CsPfwOcpvLg==; 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-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=tr0bm3pJ67Dd4eangJBgEKV1w0qdg+nx3mDSTtq1t2M=; b=KzMsXtCp1vYlcV/qgiTlld7qAJ 8XTQIQgB5v0cbBspAKTaDGuBYCOLkWYlRpuqbBe3UDtDeYKr0qLTHdBUjGeeNj0dsIyATeq8AG1OA rBbdaN7WyYPDd07VuNTdFHR8AuYXKpwDnq6QHqsQpFDDqAnymttQbn9lw2wdqOq8obkh10rIUqNm4 NTK263tC7Xv7gph4YSGae8I/hQ277iiYK3ujgZwtDDgw8eKrITQJJDStG7x0FBULnXyb037KWkqfN HwQnWOoPYUT/T3G3+3ZE/56op2jsnFD1nShyrLl+DAvitchm6sP1W/lln8Po8BZHWGpJcpFiZPRU1 /7wu5dZw==; Received: by zero.zsh.org with local id 1p4yg4-000PC7-DT; Tue, 13 Dec 2022 06:22:08 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f41.google.com) smtp.remote-ip=209.85.208.41; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f41.google.com ([209.85.208.41]:37517) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1p4yfY-000OtS-7L; Tue, 13 Dec 2022 06:21:37 +0000 Received: by mail-ed1-f41.google.com with SMTP id i9so3426836edj.4 for ; Mon, 12 Dec 2022 22:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=tr0bm3pJ67Dd4eangJBgEKV1w0qdg+nx3mDSTtq1t2M=; b=l4JDHxi7kBDAZrC2PWacG/cu5B1bqunFjFo44kiV6nYtedjXJ1hXd6zUhP9stXjz57 TfLB4aHzWKAT0Z4mJwxKZjYaGP1Fh+gNQdvzBxlVW+Ok5SlxSdstuPR3d9VI/RVJnCbj NPF/ZYVcDs6u7VR/IAjZGR+nP95J+OTHBScM+gi70jKXaKWJgCMebnx4WnDpfbYBZt0k RcM7yyk8Br1GwjILlMjKf5kpdAhRyUhgOufd9H4ZqRLflq5Yuy51syoPUKc7gxscQ2rR DDh7wXzMX79As/Nktl/GRXrmuaSjyO80YKjQHxUk3lYJWcM/S9N0R5cMRT61fbVFSpTD cTYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=tr0bm3pJ67Dd4eangJBgEKV1w0qdg+nx3mDSTtq1t2M=; b=QuzslHtw+UQu4wpyHlEgpEEPeQjW83eQqKyY2rySoHJWJXzK0jh8JztGQC26gkxphm aSdgScMk67yMZ3smV9LbtXiUbUL75Vm6TX6fWDbIJ4DM/K/jpRtFt3vcrBa5xdLUhiNJ 98Ds9fqmBnm3INui2U5H+ZYFF/lPyhh8psdhfkNlV3LZY8yYU47zl1/RaO5Nf97e6G1e OBzhPbQjG6OcMRxzJjtKBE0DnA+R4kbnMhHV+vHL/gR+ysKaUQG5gQDn67BhMu11Tx4W uKS34kQA5qsHGvfAombN4IIQBzXFt3yPZWllBFQn66MVT4SE8dn0jH0in4MDt31X3jNj RDBQ== X-Gm-Message-State: ANoB5pl41RGLNXa4c4PXfeszmbTmA1RnCdd7baUBKpl5bqs54nP/SzqN 2VyeeW9lVLJboETCnXc3pQI1NoDWdYCc6EI/fqGcPJBx30LzBlDU X-Google-Smtp-Source: AA0mqf448gs4gXeSxUhy7209VlXqCvZEeHqgOC69WlVhrAJGb2aHGmaI8u4QoMQp2UllkF+X7G46WdgmUBDryV/GAfo= X-Received: by 2002:aa7:c055:0:b0:45a:1af2:ed6d with SMTP id k21-20020aa7c055000000b0045a1af2ed6dmr69619268edo.364.1670912495691; Mon, 12 Dec 2022 22:21:35 -0800 (PST) MIME-Version: 1.0 References: <20221211175001.u7dqfrnnzylsbjan@chazelas.org> In-Reply-To: <20221211175001.u7dqfrnnzylsbjan@chazelas.org> From: Bart Schaefer Date: Mon, 12 Dec 2022 22:21:24 -0800 Message-ID: Subject: Re: a='foo"'; echo ${a/foo"/"bar} outputs bar To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 51202 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: On Sun, Dec 11, 2022 at 9:50 AM Stephane Chazelas wrote: > > $ a='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. > 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. This was actually caught at paramsubst() line 3118: haserr = parse_subst_string(s); This returned haserr == 1, but the only effect of that is that the string is retokenized at line 3124. If you use ${(X)x/foo"/"bar} you get zsh: unmatched " Next question is where this should be fixed. The following works for double-quotes, but not single because of special handling required for $'...' -- so should be considered only a proof of how the substitution could work with more conventional quoting. All tests still pass with the below. diff --git a/Src/subst.c b/Src/subst.c index 0f98e6ea3..86ee1dad8 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2911,6 +2911,9 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, else ptr++; } + if (c == Dnull) + while (ptr[1] && ptr[1] != c) + ptr++; } replstr = (*ptr && ptr[1]) ? ptr+1 : ""; *ptr = '\0';