diff --git a/p2p/_utils.py b/p2p/_utils.py index 3a2bdbbc6f..afa9336348 100644 --- a/p2p/_utils.py +++ b/p2p/_utils.py @@ -117,5 +117,8 @@ def trim_middle(arbitrary_string: str, max_length: int) -> str: half_len, is_odd = divmod(max_length, 2) first_half = arbitrary_string[:half_len - 1] last_half_len = half_len - 2 + is_odd - last_half = arbitrary_string[last_half_len * -1:] + if last_half_len > 0: + last_half = arbitrary_string[last_half_len * -1:] + else: + last_half = '' return f"{first_half}✂✂✂{last_half}" diff --git a/setup.py b/setup.py index 3e4f38cd97..3f94a347d5 100644 --- a/setup.py +++ b/setup.py @@ -96,7 +96,7 @@ 'libp2p': [ "base58>=1.0.3", # use the forked multiaddr temporarily until the fixing changes are released - "multiaddr @ git+https://git@github.com/mhchia/py-multiaddr@feature/add-unix-proto", + "multiaddr>=0.0.7,<0.1.0", "protobuf>=3.6.1", "pymultihash>=0.8.2", ], diff --git a/tests/p2p/test_utils.py b/tests/p2p/test_utils.py index c770cce307..1a0790813e 100644 --- a/tests/p2p/test_utils.py +++ b/tests/p2p/test_utils.py @@ -14,6 +14,7 @@ ("notcut", 6, "notcut"), ("tobecut", 6, "to✂✂✂t"), ("tobecut", 5, "t✂✂✂t"), + ("0000", 3, "✂✂✂"), ("really long thing with a bunch of garbage", 20, "really lo✂✂✂ garbage"), ) )