From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3A09713835A for ; Mon, 24 May 2021 06:20:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 70922E0821; Mon, 24 May 2021 06:20:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 58A25E0821 for ; Mon, 24 May 2021 06:20:09 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B4F35335C78 for ; Mon, 24 May 2021 06:20:07 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1B879720 for ; Mon, 24 May 2021 06:20:06 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1621837033.0339031c22f3e30d95d1234ce08a47ae5df8e3f8.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/tests/ebuild/test_shell_quote.py X-VCS-Directories: lib/portage/tests/ebuild/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 0339031c22f3e30d95d1234ce08a47ae5df8e3f8 X-VCS-Branch: master Date: Mon, 24 May 2021 06:20:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 51e2a0ae-c953-429e-93d8-72b8488abdf6 X-Archives-Hash: cbe0e841a71b29d0adcab87eb43d9d50 commit: 0339031c22f3e30d95d1234ce08a47ae5df8e3f8 Author: Felix Bier gmail com> AuthorDate: Tue May 18 20:53:11 2021 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon May 24 06:17:13 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=0339031c Add unit tests for _shell_quote This commit adds unit tests that cover the existing functionality of _shell_quote, by checking that various special characters are escaped/quoted correctly. Signed-off-by: Felix Bier rohde-schwarz.com> Signed-off-by: Zac Medico gentoo.org> lib/portage/tests/ebuild/test_shell_quote.py | 79 ++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lib/portage/tests/ebuild/test_shell_quote.py b/lib/portage/tests/ebuild/test_shell_quote.py new file mode 100644 index 000000000..ce419488a --- /dev/null +++ b/lib/portage/tests/ebuild/test_shell_quote.py @@ -0,0 +1,79 @@ +# Copyright 2021 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +from portage import _shell_quote +from portage.tests import TestCase + +class ShellQuoteTestCase(TestCase): + + def testShellQuote(self): + test_data = [ + + # String contains no special characters, should be preserved. + ("abc","abc"), + + # String contains whitespace, should be double-quoted to prevent word splitting. + ("abc xyz","\"abc xyz\""), + ("abc xyz","\"abc xyz\""), + (" abcxyz ","\" abcxyz \""), + ("abc\txyz","\"abc\txyz\""), + ("abc\t\txyz","\"abc\t\txyz\""), + ("\tabcxyz\t","\"\tabcxyz\t\""), + ("abc\nxyz","\"abc\nxyz\""), + ("abc\n\nxyz","\"abc\n\nxyz\""), + ("\nabcxyz\n","\"\nabcxyz\n\""), + + # String contains > or <, should be double-quoted to prevent redirection. + ("abc>xyz","\"abc>xyz\""), + ("abc>>xyz","\"abc>>xyz\""), + (">abcxyz>","\">abcxyz>\""), + ("abc