UnicodeDecodeError from bzr version when log file has non-ascii path

Bug #312841 reported by Mark Hammond
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
Low
Martin Packman

Bug Description

consider the following on Windows:

c:\>set BZR_HOME=\temp\test_©har
[do some bzr stuff...]
c:\>dir %BZR_HOME%
 Directory of O:\temp\test_©har
...
01/01/2009 07:57 PM 5,233 .bzr.log
c:\>bzr version
...
  File "O:\src\bazaar\bzr\bzr.work\bzrlib\version.py", line 78, in show_version
    to_file.write(trace._bzr_log_filename + '\n')
  File "o:\src\python-2.5-svn\lib\codecs.py", line 303, in write
    data, consumed = self.encode(object, self.errors)
  File "o:\src\python-2.5-svn\lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa9 in position 11: ordinal not in range(128)

Related branches

Revision history for this message
Mark Hammond (mhammond) wrote :

This is fixed with:

=== modified file 'bzrlib/version.py'
--- bzrlib/version.py 2008-04-02 00:14:00 +0000
+++ bzrlib/version.py 2009-01-01 09:10:31 +0000
@@ -75,7 +75,10 @@
             config_dir = config_dir.decode(osutils.get_user_encoding())
         to_file.write(" Bazaar configuration: %s\n" % (config_dir,))
         to_file.write(" Bazaar log file: ")
- to_file.write(trace._bzr_log_filename + '\n')
+ log_fn = trace._bzr_log_filename
+ if not isinstance(log_fn, unicode):
+ log_fn = log_fn.decode(sys.getfilesystemencoding())
+ to_file.write(log_fn + '\n')
     if show_copyright:
         to_file.write('\n')
         to_file.write(bzrlib.__copyright__ + '\n')

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 312841] Re: BZR_HOME with extended char causes 'bzr version' to fail

On Thu, 2009-01-01 at 09:12 +0000, Mark Hammond wrote:
> This is fixed with:

Looks sensible to me; do you think its possible to write a test case for
it?

-Rob
--
GPG key available at: <http://www.robertcollins.net/keys.txt>.

Revision history for this message
Mark Hammond (mhammond) wrote : Re: BZR_HOME with extended char causes 'bzr version' to fail

> Looks sensible to me; do you think its possible to write a test case for
> it?

I expect so, given how simple the repro is. I'd expect it might also be possible to reproduce on Linux, so long as the bytes fetched from os.environ() aren't encodable in the stdout encoding. That might be a better first step, so any tests and failure cases can be sure to be portable.

Revision history for this message
Vincent Ladeuil (vila) wrote :

marking 'in progress' but leaving the unassigned because a patch is available in the comments (but a test is lacking).

Changed in bzr:
importance: Undecided → Low
status: New → In Progress
Martin Packman (gz)
summary: - BZR_HOME with extended char causes 'bzr version' to fail
+ UnicodeDecodeError from bzr version when log file has non-ascii path
Jelmer Vernooij (jelmer)
Changed in bzr:
status: In Progress → Won't Fix
status: Won't Fix → Confirmed
Martin Packman (gz)
Changed in bzr:
assignee: nobody → Martin Packman (gz)
status: Confirmed → In Progress
Martin Packman (gz)
Changed in bzr:
milestone: none → 2.5b6
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.