diff --git a/multiaddr/transforms.py b/multiaddr/transforms.py index b366f59..869fe49 100644 --- a/multiaddr/transforms.py +++ b/multiaddr/transforms.py @@ -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: diff --git a/newsfragments/112.bugfix b/newsfragments/112.bugfix new file mode 100644 index 0000000..306f454 --- /dev/null +++ b/newsfragments/112.bugfix @@ -0,0 +1 @@ +Fix `string_iter` to correctly handle unix paths and other path protocols by consuming remaining components diff --git a/tests/test_transforms.py b/tests/test_transforms.py index cb2f53b..85ea512 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -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"