##// END OF EJS Templates
Prevent completion on keys with garbage in it
Corentin Cadiou -
Show More
@@ -780,14 +780,20 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre'
780 780 """
781 781 prefix_tuple = extra_prefix if extra_prefix else ()
782 782 Nprefix = len(prefix_tuple)
783 def filter_by_prefix_tuple(key):
783 def filter_prefix_tuple(key):
784 # Reject too short keys
784 785 if len(key) <= Nprefix:
785 786 return False
787 # Reject keys with non str/bytes in it
788 for k in key:
789 if not isinstance(k, (str, bytes)):
790 return False
791 # Reject keys that do not match the prefix
786 792 for k, pt in zip(key, prefix_tuple):
787 793 if k != pt:
788 794 return False
789 else:
790 return True
795 # All checks passed!
796 return True
791 797
792 798 filtered_keys:List[Union[str,bytes]] = []
793 799 def _add_to_filtered_keys(key):
@@ -796,7 +802,7 b' def match_dict_keys(keys: List[Union[str, bytes, Tuple[Union[str, bytes]]]], pre'
796 802
797 803 for k in keys:
798 804 if isinstance(k, tuple):
799 if filter_by_prefix_tuple(k):
805 if filter_prefix_tuple(k):
800 806 _add_to_filtered_keys(k[Nprefix])
801 807 else:
802 808 _add_to_filtered_keys(k)
@@ -920,12 +920,16 b' class TestCompleter(unittest.TestCase):'
920 920 "bad": None,
921 921 object(): None,
922 922 5: None,
923 ("abe", None): None,
924 (None, "abf"): None
923 925 }
924 926
925 927 _, matches = complete(line_buffer="d['a")
926 928 nt.assert_in("abc", matches)
927 929 nt.assert_in("abd", matches)
928 930 nt.assert_not_in("bad", matches)
931 nt.assert_not_in("abe", matches)
932 nt.assert_not_in("abf", matches)
929 933 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
930 934
931 935 # check escaping and whitespace
General Comments 0
You need to be logged in to leave comments. Login now