[Reportbug-maint] Bug#492240: reportbug: Can't include non ascii files

Flavio Grossi FlavioGrossi at jumpy.it
Thu Jul 24 16:21:24 UTC 2008

Package: reportbug
Version: 3.43
Severity: normal
Tags: patch

Don't know if this is related to bug number 491869, since i cannot
reproduce that bug

Trying to include a file with non ascii contents or filename in a bug
report raises an uncaught exception:

$ cat test¼
some strange chars here:
¼ € ¢ æ

$ reportbug -i test¼ reportbug
Detected character set: UTF-8
Please change your locale if this is incorrect.

Using 'Flavio Grossi <FlavioGrossi at jumpy.it>' as your from address.
Traceback (most recent call last):
File "/usr/bin/reportbug", line 1823, in <module>
File "/usr/bin/reportbug", line 848, in main
  return iface.user_interface()
File "/usr/bin/reportbug", line 1065, in user_interface
  incfiles = u'%s\n*** %s\n%s' % (incfiles, f, fp.read().decode('utf-8', 'replace'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4: ordinal not in range(128)

Using the gui interface, choosing "Include a text file" option and
selecting the same file, raises

Traceback (most recent call last):
File "/usr/bin/reportbug", line 1823, in <module>
File "/usr/bin/reportbug", line 848, in main
  return iface.user_interface()
File "/usr/bin/reportbug", line 1764, in user_interface
File "/usr/bin/reportbug", line 227, in handle_editing
  attachfile, inline=inline)
File "/usr/bin/reportbug", line 126, in include_file_in_report
  message += '\n*** %s\n%s' % (include_filename, fp.read())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 9: ordinal not in range(128)

Attached is a patch that should fix both problems.

-- Package-specific info:
** Environment settings:

** /home/flavio/.reportbugrc:
reportbug_version "3.43"
mode standard
ui urwid
realname "Flavio Grossi"
email "FlavioGrossi at jumpy.it"
header "X-Debbugs-CC: FlavioGrossi at jumpy.it"
smtphost bugs.debian.org

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.25-custom.1 (SMP w/1 CPU core)
Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages reportbug depends on:
ii  apt                           0.7.14+b1  Advanced front-end for dpkg
ii  python                        2.5.2-1    An interactive high-level object-o
ii  python-central                0.6.8      register and build utility for Pyt

reportbug recommends no packages.

Versions of packages reportbug suggests:
pn  debconf-utils                 <none>     (no description available)
pn  debsums                       <none>     (no description available)
pn  dlocate                       <none>     (no description available)
ii  exim4-daemon-light [mail-tran 4.69-6     lightweight Exim MTA (v4) daemon
ii  file                          4.25-1     Determines file type using "magic"
ii  gnupg                         1.4.9-2    GNU privacy guard - a free PGP rep
ii  python-urwid          curses-based UI/widget library for

-- no debconf information
-------------- next part --------------
--- /usr/bin/reportbug	2008-07-17 20:21:47.000000000 +0200
+++ reportbug_fixed	2008-07-24 17:45:55.000000000 +0200
@@ -96,7 +96,7 @@
 def include_file_in_report(message, message_filename,
                            attachment_filenames, package_name,
-                           include_filename, inline=False):
+                           include_filename, charset, inline=False):
     """ Include a file in the report.
@@ -123,11 +123,13 @@
     if inline:
             fp = file(include_filename)
-            message += '\n*** %s\n%s' % (include_filename, fp.read())
+            message += '\n*** %s\n%s' % (
+                       include_filename.decode(charset, 'replace'),
+                       fp.read().decode(charset, 'replace'))
             fp, temp_filename = TempFile(
-            fp.write(message)
+            fp.write(message.encode(charset, 'replace'))
             message_filename = temp_filename
@@ -224,7 +226,7 @@
                         inline = (x == 'i')
                         (message, filename, attachments) = include_file_in_report(
                             message, filename, attachments, package,
-                            attachfile, inline=inline)
+                            attachfile, charset, inline=inline)
                         if not inline:
                             skip_editing = True
@@ -1062,7 +1064,9 @@
             for f in self.options.include:
                 if os.path.exists(f):
                     fp = file(f)
-                    incfiles = u'%s\n*** %s\n%s' % (incfiles, f, fp.read().decode('utf-8', 'replace'))
+                    incfiles = u'%s\n*** %s\n%s' % (
+                               incfiles, f.decode('utf-8', 'replace'),
+                               fp.read().decode('utf-8', 'replace'))
                     ewrite("Can't find %s to include!\n", f)

More information about the Reportbug-maint mailing list