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