Merge pull request #1021 from smartdec/select/fix-shlex-unicode

FIX - Fixes dropdown problem with non latin options
This commit is contained in:
Sarina Canelake
2013-10-24 08:17:15 -07:00
3 changed files with 8 additions and 3 deletions

View File

@@ -90,4 +90,5 @@ Nick Parlante <nick.parlante@cs.stanford.edu>
Marko Seric <marko.seric@math.uzh.ch>
Felipe Montoya <felipe.montoya@edunext.co>
Julia Hansbrough <julia@edx.org>
Nicolas Chevalier <nicolas.chevalier@epitech.eu>
Pavel Yushchenko <pavelyushchenko@gmail.com>
Nicolas Chevalier <nicolas.chevalier@epitech.eu>

View File

@@ -309,13 +309,13 @@ class OptionInput(InputTypeBase):
id==description for now. TODO: make it possible to specify different id and descriptions.
"""
# parse the set of possible options
lexer = shlex.shlex(options[1:-1])
lexer = shlex.shlex(options[1:-1].encode('utf8'))
lexer.quotes = "'"
# Allow options to be separated by whitespace as well as commas
lexer.whitespace = ", "
# remove quotes
tokens = [x[1:-1] for x in list(lexer)]
tokens = [x[1:-1].decode('utf8') for x in lexer]
# make list of (option_id, option_description), with description=id
return [(t, t) for t in tokens]

View File

@@ -75,6 +75,10 @@ class OptionInputTest(unittest.TestCase):
check("('a', 'b')", ['a', 'b'])
check("('a b','b')", ['a b', 'b'])
check("('My \"quoted\"place','b')", ['My \"quoted\"place', 'b'])
check(u"('б','в')", [u'б', u'в'])
check(u"('б', 'в')", [u'б', u'в'])
check(u"('б в','в')", [u'б в', u'в'])
check(u"('Мой \"кавыки\"место','в')", [u'Мой \"кавыки\"место', u'в'])
class ChoiceGroupTest(unittest.TestCase):