You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2020/06/03 16:05:27 UTC

[allura] 05/12: [#8361] work around formencode problems with Files/bytes

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit c44018882bd3edf210e74134722c18e0d0fdccd2
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue May 12 11:55:21 2020 -0400

    [#8361] work around formencode problems with Files/bytes
---
 Allura/allura/lib/validators.py    |  6 ++++++
 Allura/allura/lib/widgets/forms.py | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/Allura/allura/lib/validators.py b/Allura/allura/lib/validators.py
index 2dee7fc..37e6cb2 100644
--- a/Allura/allura/lib/validators.py
+++ b/Allura/allura/lib/validators.py
@@ -458,6 +458,12 @@ def convertTime(timestring):
 
 class IconValidator(fev.FancyValidator):
     regex = '(jpg|jpeg|gif|png|bmp)$'
+
+    # https://github.com/formencode/formencode/issues/101 local fix
+    # formencode is_empty doesn't handle empty bytestring by default
+    def is_empty(self, val):
+        return val == b'' or super(IconValidator, self).is_empty(val)
+
     def _to_python(self, value, state):
         p = re.compile(self.regex, flags=re.I)
         result = p.search(value.filename)
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 54082ce..d79b3ae 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -125,6 +125,20 @@ class ForgeForm(ew.SimpleForm):
                                                          ctx['errors'])
         return Markup(display)
 
+    # https://github.com/formencode/formencode/issues/101 local fix
+    def _make_schema(self):
+        schema = super(ForgeForm, self)._make_schema()
+
+        orig_val_is_iter = schema._value_is_iterator
+
+        def _value_is_iterator(val):
+            if isinstance(val, bytes):
+                return False
+            return orig_val_is_iter(val)
+        schema._value_is_iterator = _value_is_iterator
+
+        return schema
+
 
 class ForgeFormResponsive(ForgeForm):
     def __init__(self):