Show More
@@ -0,0 +1,2 b'' | |||||
|
1 | - Quotes in a filename are always escaped during tab-completion on non-Windows. | |||
|
2 | :ghpull:`10069` |
@@ -226,13 +226,13 b' def has_open_quotes(s):' | |||||
226 | return False |
|
226 | return False | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | def protect_filename(s): |
|
229 | def protect_filename(s, protectables=PROTECTABLES): | |
230 | """Escape a string to protect certain characters.""" |
|
230 | """Escape a string to protect certain characters.""" | |
231 |
if set(s) & set( |
|
231 | if set(s) & set(protectables): | |
232 | if sys.platform == "win32": |
|
232 | if sys.platform == "win32": | |
233 | return '"' + s + '"' |
|
233 | return '"' + s + '"' | |
234 | else: |
|
234 | else: | |
235 |
return "".join(("\\" + c if c in |
|
235 | return "".join(("\\" + c if c in protectables else c) for c in s) | |
236 | else: |
|
236 | else: | |
237 | return s |
|
237 | return s | |
238 |
|
238 | |||
@@ -1133,9 +1133,10 b' class IPCompleter(Completer):' | |||||
1133 | else: |
|
1133 | else: | |
1134 | if open_quotes: |
|
1134 | if open_quotes: | |
1135 | # if we have a string with an open quote, we don't need to |
|
1135 | # if we have a string with an open quote, we don't need to | |
1136 |
# protect the names |
|
1136 | # protect the names beyond the quote (and we _shouldn't_, as | |
1137 | # would cause bugs when the filesystem call is made). |
|
1137 | # it would cause bugs when the filesystem call is made). | |
1138 | matches = m0 |
|
1138 | matches = m0 if sys.platform == "win32" else\ | |
|
1139 | [protect_filename(f, open_quotes) for f in m0] | |||
1139 | else: |
|
1140 | else: | |
1140 | matches = [text_prefix + |
|
1141 | matches = [text_prefix + | |
1141 | protect_filename(f) for f in m0] |
|
1142 | protect_filename(f) for f in m0] |
@@ -274,6 +274,37 b' def test_local_file_completions():' | |||||
274 | nt.assert_true(comp.issubset(set(c))) |
|
274 | nt.assert_true(comp.issubset(set(c))) | |
275 |
|
275 | |||
276 |
|
276 | |||
|
277 | def test_quoted_file_completions(): | |||
|
278 | ip = get_ipython() | |||
|
279 | with TemporaryWorkingDirectory(): | |||
|
280 | name = "foo'bar" | |||
|
281 | open(name, 'w').close() | |||
|
282 | ||||
|
283 | # Don't escape Windows | |||
|
284 | escaped = name if sys.platform == "win32" else "foo\\'bar" | |||
|
285 | ||||
|
286 | # Single quote matches embedded single quote | |||
|
287 | text = "open('foo" | |||
|
288 | c = ip.Completer._complete(cursor_line=0, | |||
|
289 | cursor_pos=len(text), | |||
|
290 | full_text=text)[1] | |||
|
291 | nt.assert_equal(c, [escaped]) | |||
|
292 | ||||
|
293 | # Double quote requires no escape | |||
|
294 | text = 'open("foo' | |||
|
295 | c = ip.Completer._complete(cursor_line=0, | |||
|
296 | cursor_pos=len(text), | |||
|
297 | full_text=text)[1] | |||
|
298 | nt.assert_equal(c, [name]) | |||
|
299 | ||||
|
300 | # No quote requires an escape | |||
|
301 | text = '%ls foo' | |||
|
302 | c = ip.Completer._complete(cursor_line=0, | |||
|
303 | cursor_pos=len(text), | |||
|
304 | full_text=text)[1] | |||
|
305 | nt.assert_equal(c, [escaped]) | |||
|
306 | ||||
|
307 | ||||
277 | def test_jedi(): |
|
308 | def test_jedi(): | |
278 | """ |
|
309 | """ | |
279 | A couple of issue we had with Jedi |
|
310 | A couple of issue we had with Jedi |
General Comments 0
You need to be logged in to leave comments.
Login now