From patchwork Tue Feb 7 19:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132068 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51911C636D3 for ; Tue, 7 Feb 2023 19:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232169AbjBGTd5 (ORCPT ); Tue, 7 Feb 2023 14:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbjBGTdx (ORCPT ); Tue, 7 Feb 2023 14:33:53 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AF1C3B679 for ; Tue, 7 Feb 2023 11:33:36 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 8F9C4112A; Tue, 7 Feb 2023 20:33:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798415; bh=s9a5VEdd5M72aC5a/PehrFUxQ+XzrSa5PXh8d8pnvQo=; h=Date:From:To:Subject:References:In-Reply-To:From; b=hLdQT38qw/l/cikbXBgFD8GFswoRBMRJU4Rq1Vysq2qYdNRq2EQjGtO6bkrFG9tbG 6jro/wci1fUnGALCRW36ZznS/uXsaiiwl00p1MNDWXCm7o3Z9PGHAtly/Y1sFPSPFg DQFCN+iTsSKjuDLnwVIuNXK+Td7ZUf9/ZSqf4Vq87wPKYq3L/6zwf7MTZCB1QtMkjF 6bkMkWhia0v38zL49YgA8Db+h7Fe24DVYF4RtR8j79cQwZ1suiDD0Cz4UVq5TlD5dn 4eNE0uMCyQQ0mxtsn/g8g8+TG0K6yuNpX2SaUaJuDvERRTerSdlgsRKSgWQlfFgK0n 6SNrXsdrX8ckA== Date: Tue, 7 Feb 2023 20:33:34 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 3/6] fc: only parse old=new if -s, per POSIX Message-ID: <717f18e61d425cc96d2af5ac3f2c5f1de230f5d3.1675798292.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org Before (erroneously replaced): $ a=b set ... $ fc a=b 8 , b=b set After (used as search string): $ fc a=b 8 , a=b set Reported-by: Harald van Dijk Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 --- src/histedit.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index 28956ec..24631ca 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -288,21 +288,18 @@ histcmd(int argc, char **argv) } /* - * If executing, parse [old=new] now + * If -s is specified, accept [old=new] first only */ - if (lflg == 0 && argc > 0 && - ((repl = strchr(argv[0], '=')) != NULL)) { - pat = argv[0]; - *repl++ = '\0'; - argc--, argv++; + if (sflg) { + if (argc > 0 && ((repl = strchr(argv[0], '=')) != NULL)) { + pat = argv[0]; + *repl++ = '\0'; + argc--, argv++; + } + if (argc >= 2) + sh_error("too many args"); } - /* - * If -s is specified, accept only one operand - */ - if (sflg && argc >= 2) - sh_error("too many args"); - /* * determine [first] and [last] */