← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-base64-exception into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-base64-exception into launchpad:master.

Commit message:
Handle different exception raised by base64 on Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398984
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-base64-exception into launchpad:master.
diff --git a/lib/lp/code/browser/gitrepository.py b/lib/lp/code/browser/gitrepository.py
index 31f7a14..76606cd 100644
--- a/lib/lp/code/browser/gitrepository.py
+++ b/lib/lp/code/browser/gitrepository.py
@@ -23,6 +23,7 @@ __all__ = [
     ]
 
 import base64
+import binascii
 from collections import defaultdict
 
 from breezy import urlutils
@@ -990,7 +991,9 @@ class GitRepositoryPermissionsView(LaunchpadFormView):
         field_type = field_bits[0]
         try:
             ref_pattern = decode_form_field_id(field_bits[1])
-        except TypeError:
+        # base64.b32decode raises TypeError for decoding errors on Python 2,
+        # but binascii.Error on Python 3.
+        except (TypeError, binascii.Error):
             raise UnexpectedFormData(
                 "Cannot parse field name: %s" % field_name)
         if len(field_bits) > 2: