[Reportbug-commits] [reportbug] 02/03: check for valid (as per Policy) package name while handling WNPP; thanks to Paul Wise for the report; Closes: #748719
Sandro Tosi
morph at moszumanska.debian.org
Fri May 23 23:34:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
morph pushed a commit to branch master
in repository reportbug.
commit 92cebe4296c8e6b78d0b75ba809764baea78afe6
Author: Sandro Tosi <morph at debian.org>
Date: Sat May 24 00:50:58 2014 +0200
check for valid (as per Policy) package name while handling WNPP; thanks to Paul Wise for the report; Closes: #748719
---
debian/changelog | 5 ++++-
reportbug/debbugs.py | 3 +++
reportbug/utils.py | 10 ++++++++++
test/test_utils.py | 12 ++++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index cef3a30..bb17db5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,8 +8,11 @@ reportbug (6.5.1) UNRELEASED; urgency=medium
- mark it explicitly that -N/--bugnumber must receive the bug number as an
argument to the command; thanks to Ron Murray for the report;
Closes: #741369
+ * reportbug/{debbugs.py, utils.py}
+ - check for valid (as per Policy) package name while handling WNPP; thanks
+ to Paul Wise for the report; Closes: #748719
- -- Sandro Tosi <morph at debian.org> Fri, 23 May 2014 21:49:45 +0200
+ -- Sandro Tosi <morph at debian.org> Sat, 24 May 2014 00:50:03 +0200
reportbug (6.5.0) unstable; urgency=low
diff --git a/reportbug/debbugs.py b/reportbug/debbugs.py
index e21f4fd..57f23da 100644
--- a/reportbug/debbugs.py
+++ b/reportbug/debbugs.py
@@ -627,6 +627,9 @@ def handle_wnpp(package, bts, ui, fromaddr, timeout, online=True, http_proxy=Non
else:
prompt = 'Please enter the package name: '
package = ui.get_string(prompt)
+ if not utils.check_package_name(package):
+ ui.long_message('Invalid package name')
+ package = ""
ui.log_message('Checking status database...\n')
info = utils.get_package_status(package, avail=True)
diff --git a/reportbug/utils.py b/reportbug/utils.py
index af8d752..735e080 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -1214,3 +1214,13 @@ def exec_and_parse_bugscript(handler, bugscript):
text = text.decode('utf-8', 'replace')
return (rc, headers, pseudoheaders, text, attachments)
+
+def check_package_name(pkg):
+ """Check the package name against Debian Policy:
+ https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source
+
+ Returns True if the package name is valid."""
+
+ pkg_re = re.compile('^[a-z0-9][a-z0-9+-\.]+$')
+
+ return True if pkg_re.match(pkg) else False
diff --git a/test/test_utils.py b/test/test_utils.py
index f1c9e2c..ac07fce 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -583,3 +583,15 @@ class TestMisc(unittest2.TestCase):
self.assertIn('From: morph at dummy.int', h)
self.assertIn('User: morph at debian.org', ph)
self.assertIn('/etc/fstab', a)
+
+ def test_check_package_name(self):
+ self.assertTrue(utils.check_package_name('reportbug'))
+ self.assertTrue(utils.check_package_name('ab'))
+ self.assertFalse(utils.check_package_name('a'))
+ self.assertFalse(utils.check_package_name('.a'))
+ self.assertFalse(utils.check_package_name('dfffff '))
+ self.assertFalse(utils.check_package_name('reportbug_reportbug'))
+ self.assertTrue(utils.check_package_name('reportbug+love-war.com'))
+ self.assertTrue(utils.check_package_name('reportbug2001'))
+ self.assertFalse(utils.check_package_name('UPPERCASE'))
+ self.assertFalse(utils.check_package_name('((()))'))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git
More information about the Reportbug-commits
mailing list