##// END OF EJS Templates
Fix completer crash with certain unicode inputs....
Fernando Perez -
Show More
@@ -83,6 +83,7 from IPython.core.prefilter import ESC_MAGIC
83 83 from IPython.utils import generics
84 84 from IPython.utils import io
85 85 from IPython.utils.dir2 import dir2
86 from IPython.utils.process import arg_split
86 87
87 88 #-----------------------------------------------------------------------------
88 89 # Globals
@@ -473,7 +474,7 class IPCompleter(Completer):
473 474 current (as of Python 2.3) Python readline it's possible to do
474 475 better."""
475 476
476 #io.rprint('Completer->file_matches: <%s>' % text) # dbg
477 #io.rprint('Completer->file_matches: <%r>' % text) # dbg
477 478
478 479 # chars that require escaping with backslash - i.e. chars
479 480 # that readline treats incorrectly as delimiters, but we
@@ -488,7 +489,8 class IPCompleter(Completer):
488 489 text_until_cursor = self.text_until_cursor
489 490 open_quotes = 0 # track strings with open quotes
490 491 try:
491 lsplit = shlex.split(text_until_cursor)[-1]
492 # arg_split ~ shlex.split, but with unicode bugs fixed by us
493 lsplit = arg_split(text_until_cursor)[-1]
492 494 except ValueError:
493 495 # typically an unmatched ", or backslash without escaped char.
494 496 if text_until_cursor.count('"')==1:
@@ -62,6 +62,24 def test_line_split():
62 62 ('cd "some_file/', '', 'some_file/'),
63 63 ]
64 64 check_line_split(sp, t)
65 # Ensure splitting works OK with unicode by re-running the tests with
66 # all inputs turned into unicode
67 check_line_split(sp, [ map(unicode, p) for p in t] )
68
69
70 def test_unicode_completions():
71 ip = get_ipython()
72 # Some strings that trigger different types of completion. Check them both
73 # in str and unicode forms
74 s = ['ru', '%ru', 'cd /', 'floa', 'float(x)/']
75 for t in s + map(unicode, s):
76 # We don't need to check exact completion values (they may change
77 # depending on the state of the namespace, but at least no exceptions
78 # should be thrown and the return value should be a pair of text, list
79 # values.
80 text, matches = ip.complete(t)
81 nt.assert_true(isinstance(text, basestring))
82 nt.assert_true(isinstance(matches, list))
65 83
66 84
67 85 class CompletionSplitterTestCase(unittest.TestCase):
General Comments 0
You need to be logged in to leave comments. Login now