[dak/bpo] utf-8
enforce properly encoded changes/dsc files. if they do not pass
unicode() they wont get in.
Signed-off-by: Joerg Jaspert <joerg@debian.org>
---
dak/check_archive.py | 3 +++
dak/check_proposed_updates.py | 3 +++
dak/examine_package.py | 5 ++++-
dak/process_unchecked.py | 6 ++++++
daklib/dak_exceptions.py | 3 ++-
daklib/utils.py | 4 ++++
6 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/dak/check_archive.py b/dak/check_archive.py
index 8078290..bed974d 100755
--- a/dak/check_archive.py
+++ b/dak/check_archive.py
@@ -161,6 +161,9 @@ def check_dscs():
except InvalidDscError, line:
utils.warn("syntax error in .dsc file '%s', line %s." % (f, line))
count += 1
+ except ChangesUnicodeError:
+ utils.warn("found invalid changes file, not properly utf-8 encoded")
+ count += 1
if count:
utils.warn("Found %s invalid .dsc files." % (count))
diff --git a/dak/check_proposed_updates.py b/dak/check_proposed_updates.py
index f12df87..16a9876 100755
--- a/dak/check_proposed_updates.py
+++ b/dak/check_proposed_updates.py
@@ -176,6 +176,9 @@ def check_changes (filename):
try:
changes = utils.parse_changes(filename)
files = utils.build_file_list(changes)
+ except ChangesUnicodeError:
+ utils.warn("Improperly encoded changes file, not utf-8")
+ return
except:
utils.warn("Error parsing changes file '%s'" % (filename))
return
diff --git a/dak/examine_package.py b/dak/examine_package.py
index d0e1e53..eb60279 100755
--- a/dak/examine_package.py
+++ b/dak/examine_package.py
@@ -470,7 +470,10 @@ def display_changes(suite, changes_filename):
foldable_output(changes_filename, "changes", changes, norow=True)
def check_changes (changes_filename):
- changes = utils.parse_changes (changes_filename)
+ try:
+ changes = utils.parse_changes (changes_filename)
+ except ChangesUnicodeError:
+ utils.warn("Encoding problem with changes file %s" % (changes_filename))
display_changes(changes['distribution'], changes_filename)
files = utils.build_file_list(changes)
diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py
index 2e60435..288563a 100755
--- a/dak/process_unchecked.py
+++ b/dak/process_unchecked.py
@@ -186,6 +186,9 @@ def check_changes():
except ParseChangesError, line:
reject("%s: parse error, can't grok: %s." % (filename, line))
return 0
+ except ChangesUnicodeError:
+ reject("%s: changes file not proper utf-8" % (filename))
+ return 0
# Parse the Files field from the .changes into another dictionary
try:
@@ -695,6 +698,9 @@ def check_dsc():
reject("%s: parse error, can't grok: %s." % (dsc_filename, line))
except InvalidDscError, line:
reject("%s: syntax error on line %s." % (dsc_filename, line))
+ except ChangesUnicodeError:
+ reject("%s: dsc file not proper utf-8." % (dsc_filename))
+
# Build up the file list of files mentioned by the .dsc
try:
dsc_files.update(utils.build_file_list(dsc, is_a_dsc=1))
diff --git a/daklib/dak_exceptions.py b/daklib/dak_exceptions.py
index d18bee1..33fa5ad 100755
--- a/daklib/dak_exceptions.py
+++ b/daklib/dak_exceptions.py
@@ -58,7 +58,8 @@ dakerrors = {
"NoFreeFilenameError": """Exception raised when no alternate filename was found.""",
"TransitionsError": """Exception raised when transitions file can't be parsed.""",
"NoSourceFieldError": """Exception raised - we cant find the source - wtf?""",
- "DBUpdateError": """Exception raised - could not update the database"""
+ "DBUpdateError": """Exception raised - could not update the database""",
+ "ChangesUnicodeError": """Exception raised - changes file not properly utf-8 encoded"""
} #: All dak exceptions
def construct_dak_exception(name, description):
diff --git a/daklib/utils.py b/daklib/utils.py
index b20a063..e0bdfe8 100755
--- a/daklib/utils.py
+++ b/daklib/utils.py
@@ -234,6 +234,10 @@ def parse_changes(filename, signing_rules=0):
changes_in = open_file(filename)
content = changes_in.read()
changes_in.close()
+ try:
+ unicode(content, 'utf-8')
+ except UnicodeError:
+ raise ChangesUnicodeError, "Changes file not proper utf-8"
return parse_deb822(content, signing_rules)
################################################################################
--
1.5.6.5
Reply to: