Rev 5529: Report error if a non-ASCII command option is given. in http://bazaar.launchpad.net/~vila/bzr/integration/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Nov 6 15:32:01 GMT 2010


At http://bazaar.launchpad.net/~vila/bzr/integration/

------------------------------------------------------------
revno: 5529 [merge]
revision-id: v.ladeuil+lp at free.fr-20101106153200-r2uoqbrp15xdj3vv
parent: v.ladeuil+lp at free.fr-20101106152649-yxl1fgzbcgnns6vd
parent: rory.yorke at gmail.com-20101029171102-h909yz66ijeq6jnh
fixes bug(s): https://launchpad.net/bugs/140563
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: trunk
timestamp: Sat 2010-11-06 16:32:00 +0100
message:
  Report error if a non-ASCII command option is given.
modified:
  bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
  bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2010-10-08 06:22:30 +0000
+++ b/bzrlib/commands.py	2010-10-29 17:07:42 +0000
@@ -815,7 +815,13 @@
     else:
         args = argv
 
-    options, args = parser.parse_args(args)
+    # for python 2.5 and later, optparse raises this exception if a non-ascii
+    # option name is given.  See http://bugs.python.org/issue2931
+    try:
+        options, args = parser.parse_args(args)
+    except UnicodeEncodeError,e:
+        raise errors.BzrCommandError('Only ASCII permitted in option names')
+
     opts = dict([(k, v) for k, v in options.__dict__.iteritems() if
                  v is not option.OptionParser.DEFAULT_VALUE])
     return args, opts

=== modified file 'bzrlib/tests/blackbox/test_exceptions.py'
--- a/bzrlib/tests/blackbox/test_exceptions.py	2010-02-17 17:11:16 +0000
+++ b/bzrlib/tests/blackbox/test_exceptions.py	2010-11-06 15:32:00 +0000
@@ -48,6 +48,18 @@
         self.assertContainsRe(err, r'Bazaar has encountered an internal error')
 
 
+class TestOptParseBugHandling(TestCase):
+    "Test that we handle http://bugs.python.org/issue2931"
+
+    def test_nonascii_optparse(self):
+        """Reasonable error raised when non-ascii in option name"""
+        if sys.version_info < (2,5):
+            error_re = 'no such option'
+        else:
+            error_re = 'Only ASCII permitted in option names'
+        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
+
+
 class TestDeprecationWarning(tests.TestCaseWithTransport):
     """The deprecation warning is controlled via a global variable:
     repository._deprecation_warning_done. As such, it can be emitted only once

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2010-11-06 15:26:49 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2010-11-06 15:32:00 +0000
@@ -33,6 +33,8 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* Report error if non-ASCII command option given. (Rory Yorke, #140563)
+
 Documentation
 *************
 
@@ -53,6 +55,10 @@
 Testing
 *******
 
+.. Fixes and changes that are only relevant to bzr's test framework and 
+   suite.  This can include new facilities for writing tests, fixes to 
+   spurious test failures and changes to the way things should be tested.
+
 * Blank output section in scriptrunner tests no longer match any output.
   Instead, use '...' as a wildcard if you don't care about the output.
   (Martin Pool, #637830)



More information about the bazaar-commits mailing list