Merge lp:~gz/bzr/non_ascii_bzr_log_312841 into lp:bzr/2.5

Proposed by Martin Packman
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6469
Proposed branch: lp:~gz/bzr/non_ascii_bzr_log_312841
Merge into: lp:bzr/2.5
Prerequisite: lp:~gz/bzr/get_home_dir
Diff against target: 64 lines (+26/-7)
3 files modified
bzrlib/tests/blackbox/test_version.py (+17/-0)
bzrlib/trace.py (+6/-7)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~gz/bzr/non_ascii_bzr_log_312841
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) Approve
Review via email: mp+91076@code.launchpad.net

Commit message

Store the path to .bzr.log as unicode so it can be safely printed by `bzr version`

Description of the change

Fixes a UnicodeDecodeError where someone has a non-ascii home dir or sets one of the variables used to influence the location of .bzr.log to a non-ascii value. As per other changes along these, the trade off is that someone who sets BZR_LOG on a posix system to some random bytestring not in their locale will now get an error. That's a less likely scenario and can't be fixed without some bigger changes to how bzr deals with paths.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Wed, Feb 01, 2012 at 01:49:33PM -0000, Martin Packman wrote:
> Martin Packman has proposed merging lp:~gz/bzr/non_ascii_bzr_log_312841 into lp:bzr/2.5 with lp:~gz/bzr/get_home_dir as a prerequisite.
>
> Requested reviews:
> bzr-core (bzr-core)
> Related bugs:
> Bug #312841 in Bazaar: "UnicodeDecodeError from bzr version when log file has non-ascii path"
> https://bugs.launchpad.net/bzr/+bug/312841
>
> For more details, see:
> https://code.launchpad.net/~gz/bzr/non_ascii_bzr_log_312841/+merge/91076
>
> Fixes a UnicodeDecodeError where someone has a non-ascii home dir or sets one of the variables used to influence the location of .bzr.log to a non-ascii value. As per other changes along these, the trade off is that someone who sets BZR_LOG on a posix system to some random bytestring not in their locale will now get an error. That's a less likely scenario and can't be fixed without some bigger changes to how bzr deals with paths.

I'm sure there's a unicode symbol symbol expressing approval
somewhere, but I can't find it at the moment. For now, then:

  merge approve

Cheers,

Jelmer

review: Approve
Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/blackbox/test_version.py'
2--- bzrlib/tests/blackbox/test_version.py 2011-05-13 12:51:05 +0000
3+++ bzrlib/tests/blackbox/test_version.py 2012-02-01 17:15:21 +0000
4@@ -129,3 +129,20 @@
5 self.assertTrue(len(out) > 0)
6 self.assertContainsRe(out, r"(?m)^ Bazaar log file: " + bzr_log)
7 self.assertPathDoesNotExist(default_log)
8+
9+ def test_unicode_bzr_log(self):
10+ uni_val = u"\xa7"
11+ enc = osutils.get_user_encoding()
12+ try:
13+ str_val = uni_val.encode(enc)
14+ except UnicodeEncodeError:
15+ self.skip("Test string %r unrepresentable in user encoding %s" % (
16+ uni_val, enc))
17+ self.overrideEnv('BZR_HOME', self.test_base_dir)
18+ self.overrideEnv("BZR_LOG",
19+ os.path.join(self.test_base_dir, uni_val).encode(enc))
20+ out, err = self.run_bzr_subprocess("version")
21+ uni_out = out.decode(enc)
22+ self.assertContainsRe(uni_out, u"(?m)^ Bazaar log file: .*/\xa7$")
23+
24+
25
26=== modified file 'bzrlib/trace.py'
27--- bzrlib/trace.py 2011-12-19 13:23:58 +0000
28+++ bzrlib/trace.py 2012-02-01 17:15:21 +0000
29@@ -194,16 +194,15 @@
30
31
32 def _get_bzr_log_filename():
33- bzr_log = os.environ.get('BZR_LOG')
34+ bzr_log = osutils.path_from_environ('BZR_LOG')
35 if bzr_log:
36 return bzr_log
37- home = os.environ.get('BZR_HOME')
38+ home = osutils.path_from_environ('BZR_HOME')
39 if home is None:
40- if sys.platform == 'win32':
41- from bzrlib import win32utils
42- home = win32utils.get_home_location()
43- else:
44- home = os.path.expanduser('~')
45+ # GZ 2012-02-01: Logging to the home dir is bad, but XDG is unclear
46+ # over what would be better. On windows, bug 240550
47+ # suggests LOCALAPPDATA be used instead.
48+ home = osutils._get_home_dir()
49 return os.path.join(home, '.bzr.log')
50
51
52
53=== modified file 'doc/en/release-notes/bzr-2.5.txt'
54--- doc/en/release-notes/bzr-2.5.txt 2012-01-31 18:25:57 +0000
55+++ doc/en/release-notes/bzr-2.5.txt 2012-02-01 17:15:21 +0000
56@@ -66,6 +66,9 @@
57 * ``bzr send`` works on treeless branches again.
58 (Jelmer Vernooij, #921591)
59
60+* ``bzr version`` no longer throws a UnicodeDecodeError if the .bzr.log path
61+ contains non-ascii characters. (Martin Packman, #312841)
62+
63 * Support scripts that don't call bzrlib.initialize() but still call run_bzr().
64 (Vincent Ladeuil, #917733)
65

Subscribers

People subscribed via source and target branches