allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [01/50] git commit: [#6149] ticket:356 Fix select field value splitting
Date Fri, 24 May 2013 17:04:37 GMT
Updated Branches:
  refs/heads/db/6255 2ef1046cc -> 10f1c19ea (forced update)


[#6149] ticket:356 Fix select field value splitting

* Fall back to regular splitting if shlex.split raises exception
* Always encode unicode-strings before passing it to shlex (it doesn't work well with unicode)


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/a211a0d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a211a0d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a211a0d7

Branch: refs/heads/db/6255
Commit: a211a0d7ffa2e50e635f05188a11796c2e1da5be
Parents: 05d660d
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon May 20 08:14:39 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon May 20 17:20:30 2013 +0000

----------------------------------------------------------------------
 .../forgetracker/tests/functional/test_root.py     |   34 +++++++++++++++
 ForgeTracker/forgetracker/widgets/ticket_form.py   |   19 +++++++-
 2 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a211a0d7/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index b80e28b..6723778 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -645,6 +645,40 @@ class TestFunctionalController(TrackerTestController):
         ticket_view = self.new_ticket(summary='test select custom fields', **kw).follow()
         assert '<option selected value="test select">test select</option>' in
ticket_view
 
+    def test_select_custom_field_unicode(self):
+        params = dict(
+            custom_fields=[
+                dict(name='_testselect', label='Test', type='select',
+                     options='oné "one and á half" two'),
+               ],
+            open_status_names='aa bb',
+            closed_status_names='cc',
+            )
+        self.app.post(
+            '/admin/bugs/set_custom_fields',
+            params=variable_encode(params))
+        r = self.app.get('/bugs/new/')
+        assert u'<option value="oné">oné</option>'.encode('utf-8') in r
+        assert u'<option value="one and á half">one and á half</option>'.encode('utf-8')
in r
+        assert u'<option value="two">two</option>' in r
+
+    def test_select_custom_field_invalid_quotes(self):
+        params = dict(
+            custom_fields=[
+                dict(name='_testselect', label='Test', type='select',
+                     options='closéd "quote missing'),
+               ],
+            open_status_names='aa bb',
+            closed_status_names='cc',
+            )
+        self.app.post(
+            '/admin/bugs/set_custom_fields',
+            params=variable_encode(params))
+        r = self.app.get('/bugs/new/')
+        assert u'<option value="closéd">closéd</option>'.encode('utf-8') in
r
+        assert u'<option value="quote">quote</option>' in r
+        assert u'<option value="missing">missing</option>' in r
+
     def test_custom_field_update_comments(self):
         params = dict(
             custom_fields=[

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a211a0d7/ForgeTracker/forgetracker/widgets/ticket_form.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index f253484..5e3b61b 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -15,7 +15,6 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from allura.lib.widgets import form_fields as ffw
 import shlex
 
 from pylons import tmpl_context as c
@@ -25,6 +24,8 @@ import ew as ew_core
 import ew.jinja2_ew as ew
 
 from allura import model as M
+from allura.lib.widgets import form_fields as ffw
+from allura.lib import helpers as h
 
 class TicketCustomFields(ew.CompoundField):
     template='jinja:forgetracker:templates/tracker_widgets/ticket_custom_fields.html'
@@ -150,7 +151,21 @@ class TicketCustomField(object):
 
     def _select(field):
         options = []
-        for opt in shlex.split(field.options):
+        field_options = h.really_unicode(field.options)
+        try:
+            # shlex have problems with parsing unicode,
+            # it's better to pass properly encoded byte-string
+            field_options = shlex.split(field_options.encode('utf-8'))
+            # convert splitted string back to unicode
+            field_options = map(h.really_unicode, field_options)
+        except ValueError:
+            field_options = field_options.split()
+            # After regular split field_options might contain a " characters,
+            # which would break html when rendered inside tag's value attr.
+            # Escaping doesn't help here, 'cause it breaks EasyWidgets' validation,
+            # so we're getting rid of those.
+            field_options = [o.replace('"', '') for o in field_options]
+        for opt in field_options:
             selected = False
             if opt.startswith('*'):
                 opt = opt[1:]


Mime
View raw message