[MERGE][Bug #116143] commit raises UnicodeError (traceback) if LANG is incorrect

Daniel Watkins D.M.Watkins at warwick.ac.uk
Tue Aug 7 12:40:12 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> === modified file bzrlib/commands.py //
> last-changed:d.m.watkins at warwick.ac.uk-
> ... 20070727225945-y8qywyj9hsqrlvjc
> --- bzrlib/commands.py
> +++ bzrlib/commands.py
> @@ -718,7 +718,11 @@
>      import bzrlib.ui
>      from bzrlib.ui.text import TextUIFactory
>      bzrlib.ui.ui_factory = TextUIFactory()
> -    argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
> +    try:
> +        argv = [a.decode(bzrlib.user_encoding) for a in argv[1:]]
> +    except UnicodeDecodeError:
> +        raise errors.BzrError(("Parameter '%s' is unsupported by the
> current "
> +                                                            "encoding."
> % a))
>      ret = run_bzr_catch_errors(argv)
>      trace.mutter("return code %d", ret)
>      return ret
> 
> This seems to apply to not just commit but the arguments/options of all
> commands?  If so, the news file should say so.
Done.

> Given that we know a is unrepresentable it seems a bit provocative(?) to
> print it with %s rather than %r.
Done.

> +
> +    def test_unsupported_encoding_commit_message(self):
> +        old_env = osutils.set_or_unset_env('LANG', 'C')
> +        self.make_fake_editor(message='\xff')
> +
> +        working_tree = self.make_uncommitted_tree()
> +        self.assertRaises(errors.BadCommitMessageEncoding,
> + bzrlib.msgeditor.edit_commit_message, '')
> +
> +        osutils.set_or_unset_env('LANG', old_env)
> 
> The restoration should be in a finally block.
Done.

> +                    lastline = nlines
> +                msg.append(line)
> +            f.close()
> +        except UnicodeDecodeError:
> +            f.close()
> +            raise BadCommitMessageEncoding()
> 
> It would be cleaner to have, after the except block
Done.

- --
Daniel Watkins (Odd_Bloke)
University of Warwick Christian Focus President
University of Warwick Computing Society WUGLUG Liaison Officer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGuFob3arasOikFPYRAvsUAJ9TyzS28J/k/opaB9TKScoLlXaiDQCgulZ1
xzpSsJgJAEuDqauemaEoSaA=
=ivwh
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 116143.4.bundle
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20070807/a6844f7d/attachment.diff 


More information about the bazaar mailing list