From ff5f141bf205ad25e8ed4b8c9436b530f8ebf2be Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 1 May 2021 06:54:10 -0500 Subject: [PATCH] test: fix passwd_sanitize() 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") sys.stdout.write(l) ' }