From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MJZyNa6zjWBIAgEAgWs5BA (envelope-from ) for ; Sat, 01 May 2021 22:01:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id kLouMa6zjWBKTQAAbx9fmQ (envelope-from ) for ; Sat, 01 May 2021 20:01:50 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 147D3185AD for ; Sat, 1 May 2021 22:01:50 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id A35E3271D4; Sat, 1 May 2021 16:01:42 -0400 (EDT) Received: from lahtoruutu.iki.fi (unknown [IPv6:2a0b:5c81:1c1::37]) by mail.notmuchmail.org (Postfix) with ESMTPS id CD8DC2716D for ; Sat, 1 May 2021 16:01:39 -0400 (EDT) Received: from guru.guru-group.fi (unknown [IPv6:2a02:2380:1:9:5054:ff:feb7:a4bc]) (using TLSv1.2 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: too) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 6AA701B0102D; Sat, 1 May 2021 23:01:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1619899286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JlhSXy0IC62ozQE4hmQ0RvD+0lQXtqBEKs4mtkG9W6A=; b=X3of/rdiT1C1EjX0aBZOKtStLZvEPJP9NpcrwtrYKy0GsEUTupe9swPOWiXRJbhpzgZ6s+ Xmw1wOr5YCxrnXsxut2+LWb8RaD3AbOlEF+JupfNoPl3nHRtbOAFssid3aEE5w8/UjnMbz TLaZr5zvNex0GNJEAQV6yxI/C3zJ8RjWIbvlp9Zf+N0WwB6hzt2YS9x4NodKd/uS3EYdWv 8fyXiuuJyYntuj000A8nZZvie2Rrjwt7R9abLrACdW+oQvLppademQL3PzD+M1WQvvbfqK /BiKGdhnUxvOYPv+6bE+y8bLme/fhJdBP10NT0MAXUP6wVtxV1NG7ssqtKm/9w== From: Tomi Ollila To: Felipe Contreras , notmuch@notmuchmail.org Subject: Re: [PATCH 01/13] test: fix passwd_sanitize() In-Reply-To: <20210501115422.483314-2-felipe.contreras@gmail.com> References: <20210501115422.483314-1-felipe.contreras@gmail.com> <20210501115422.483314-2-felipe.contreras@gmail.com> User-Agent: Notmuch/0.31.4+128~gc67b63a (https://notmuchmail.org) Emacs/27.1 X-Face: HhBM'cA~ MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1619899286; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JlhSXy0IC62ozQE4hmQ0RvD+0lQXtqBEKs4mtkG9W6A=; b=h+/Qc0m409ZZwKha5d0Zn+O2T848je2FD/chtf+Lhh/rdQchDniH/We6+QBFsQLYpBy55S 4GJiG9FgCnu/R8FcD431Jy4ZxDZ8Pqqspsc1m+TQwMIxggDADhEsQqW/5NEqoPTkIihuE3 5eb+pc1Vsl8xa/P6ywaA8Mb7LHR7ulgNBa9xat6cOnaY3Md34J0DjCLOmjNtyfnoanNk3x 4diXhn2KzqiYZrAjh6T7U3jZG9yRd9Q8V78RLhsxmnFswTNKUvXfwU9qub9sQDlXvD78sW HsxmwQFgiI5oiLdhhiJH8tXSDaJVF4eb6fPG10vyosR4wWp2P/TcYhQqzlGP4Q== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=too smtp.mailfrom=tomi.ollila@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1619899286; a=rsa-sha256; cv=none; b=sYk6t4/w1qqZAvsR5Xp36QpkgMRgk1BBGfK8VrpiEhV01GwlVwZhXQkVEoi/lUY8kgBfhj MeB0x5sgt7hExHKHr/j+yHCI6AVzWJ48cOCtduF9aMwFa/aUu95ArLCjKDOnilQLaxYEKy BGMG5l/668u/coD6pSQdaFwgqnwzEamXOjDHvO2xc+YC2uFFr886tNduNj3vPkkLyYlpJ6 kDCkBIJV4RAkrCGtNNaL9gYogBrNrzgQxePGlu/L6/KO7sZdSK+zSgc6xPSWcsegi7uO3x DdtPuwjMk6zje0HpsPhP7WzP04fP9IdNn+HZCNs7jvmwE1djz+jDHh+kKb4/EQ== Message-ID-Hash: SL7L2SW22UNBCYQCIXMCGWLH2CRPDGWG X-Message-ID-Hash: SL7L2SW22UNBCYQCIXMCGWLH2CRPDGWG X-MailFrom: tomi.ollila@iki.fi X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619899310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=qoJRnPvTWQVwSVu7yZQtIHkEc1f5KyMjqh+LOxUe5Jk=; b=Gst5BNk2ki+RrzdJ5GCHqK1hwZ/6Mm+kQPVQI51QRmZDJdgXrF5X2xrPeINNPVh3XqIuFS X+NOA25/O00XDhaCkC5n/8qyf7BjSyu4TyDg6vxxIANdT5FkNB8powZLT0TauObGALpRQI fD/ZYAIeM59bq4o/dYZC35/yX1+q25zo2WbrK9JNCFI451EZBhVKxBZRyZPPBPZUy7Ub7b sbT4tkv8csvZwMQvmmAR6WzRmO8sXleMMGb2kj/y72PVID/YF8Frb251z74ZdwA57B3pCq rye79SVdBBqRHFyGYiB3ev4ZAk3sOz/N8/Y2sXCsbBVb9DeCmt84kovknWpihQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1619899310; a=rsa-sha256; cv=fail; b=WecbMhTKXHzm3bzWylaQAN5eTgYihJ1dWaYQXDcYWp0QrJjZR4nec8JLxt4VLvXpQBTbcI 3pswwAWeifDD8Mn2q94uiJ80jlyDmFM+zuk0bqE+Hd74CHqurH0ICxuF4emLrhufyRrGjm 8b7qWM+Mu8lymj0zDBsrtSatHa7tszZh3Rs/rbULcOg6M2omfTAkqwe3WmvqfpCPKeKKDu kWhrkt5SzGCp1abSCRMnJfcPNmFO7dJ2tuUA8wVp+mprh11zhEu9c0kUnlX60p54XyiyCz 5Cw2TRCIOujQGqHh8UVaPcRKso9mkglsCYUHuXRangMxDpcJ2MAJPaAWpzlNQA== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=lahtoruutu header.b="X3of/rdi"; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.90 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=iki.fi header.s=lahtoruutu header.b="X3of/rdi"; arc=reject ("signature check failed: fail, {[1] = sig:iki.fi:reject}"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 147D3185AD X-Spam-Score: 0.90 X-Migadu-Scanner: scn0.migadu.com X-TUID: 00o0c0FK6sLp On Sat, May 01 2021, Felipe Contreras wrote: > If any of the variables is empty the output is completely messed up, > because replace("", "FOO") puts "FOO" before every single character. > > I don't have my full name configured, and this is what I get: > > USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME USER_FULL_NAMEsUSER_FULL_NAMEtUSER_FULL_NAMEdUSER_FULL_NAMEoUSER_FULL_NAMEuUSER_FULL_NAMEtUSER_FULL_NAME USER_FULL_NAME=USER_FULL_NAME=USER_FULL_NAME > > Let's check for empty strings before doing any replace. > > Signed-off-by: Felipe Contreras > --- > test/test-lib.sh | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/test/test-lib.sh b/test/test-lib.sh > index 4c9f2a21..e13797a7 100644 > --- a/test/test-lib.sh > +++ b/test/test-lib.sh > @@ -711,7 +711,12 @@ name = pw.pw_gecos.partition(",")[0] > fqdn = socket.getfqdn() > > for l in sys.stdin: > - l = l.replace(user, "USERNAME").replace(fqdn, "FQDN").replace(".(none)","").replace(name, "USER_FULL_NAME") > + if user: > + l = l.replace(user, "USERNAME") > + if fqdn: > + l = l.replace(fqdn, "FQDN").replace(".(none)","") > + if name: > + l = l.replace(name, "USER_FULL_NAME") This looks like a good change. This made me think of something. When I quickly deviced the initial code of this I thinkoed that str.replace() replaces only the first match -- now that I tested (in python3 repl) it replaces *all* matches... In my home machines I usually have both "username" and "user_full_name" (using the terms used in the sanitizer) as 'too'... Currently all is lost in USER_FULL_NAME replacement -- all 'too's are replaced with USERNAME and no USER_FULL_NAME replacements happen. If we had l.replace(user, "USERNAME", 1) then only the first match were replaced -- and if both matches are expected to happen in same line -- the "full name" replacement later in line, then this change would help in such a cases. If these replacements are to be done in different lines then the USERNAME replacement would always be done and nothing helps there (except more specific replacement code)... And, now as this chance of having empty username come into our understanding, instead of empty, but some short (or why not longer) strings that just happen to be (sub)strings of the text it gets as input we get unwanted replacements and test failures... :/ Tomi > sys.stdout.write(l) > ' > } > -- > 2.31.0