Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions multiaddr/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ def string_iter(
raise exceptions.StringParseError(
f"missing value for protocol: {proto_name}", string
)
value = parts[i + 1]
i += 1 # Skip the next part since we used it as value

if getattr(codec, "IS_PATH", False):
value = "/".join(parts[i + 1 :])
i = len(parts) - 1
else:
value = parts[i + 1]
i += 1 # Skip the next part since we used it as value
logger.debug(f"[DEBUG string_iter] Using next part as value: {value}")
yield proto, codec, value
else:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/112.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `string_iter` to correctly handle unix paths and other path protocols by consuming remaining components
10 changes: 10 additions & 0 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,13 @@ def test_codec_to_string_value_error(proto, buf):
)
def test_cid_autoconvert_to_string(proto, buf, expected):
assert codec_by_name("cid").to_string(proto, buf) == expected


def test_string_iter_unix_path():
from multiaddr.transforms import string_iter

parts = list(string_iter("/unix/var/run/docker.sock"))
assert len(parts) == 1
proto, _, value = parts[0]
assert proto.name == "unix"
assert value == "var/run/docker.sock"
Loading