Skip to content

Conversation

@yashksaini-coder
Copy link
Contributor

@yashksaini-coder yashksaini-coder commented Nov 4, 2025

Fixes: #98

This pull request improves the parsing logic for multiaddresses, specifically enhancing validation for tag-only protocols (protocols that do not accept values). The changes ensure that these protocols correctly reject invalid value assignments, provide clearer error messages, and add comprehensive tests for these cases.

Parsing logic improvements:

  • Refactored the parsing loop in multiaddr.py to use an index-based approach, allowing lookahead and better validation of protocol arguments.
  • Added explicit checks to ensure tag-only protocols (with codec=None) do not accept values via either /tag/value or /tag=value syntax, raising a clear StringParseError if violated. [1] [2]
  • Improved error handling for missing or invalid protocol values, especially for the unix protocol and other value-accepting protocols. [1] [2]

Testing enhancements:

  • Added new tests in test_multiaddr.py to verify that tag-only protocols reject values with both /tag/value and /tag=value syntaxes, and that valid combinations are accepted.
  • Improved test coverage for error message clarity, ensuring that error messages for tag-only protocols are helpful and do not include the invalid value.

After implementing the changes, we get proper accept values

image

@seetadev @Nkovaturient @lla-dane Please review this pull request changes.

… values. Introduced list-based iteration for better validation and error handling, ensuring correct processing of 'unix' paths and flag protocols. Added checks for missing values and invalid arguments for protocols without associated values.
Implemented unit tests to ensure tag-only protocols reject invalid value syntax (both /tag/value and /tag=value) and validate correct combinations. Enhanced error message clarity for invalid inputs.
@yashksaini-coder yashksaini-coder changed the title Fix/98 Fix Tag-Only Protocols validation error Nov 4, 2025
- Encode protocol code for tag-only protocols before validation check
  This fixes the bug where tag-only protocols (e.g., http, tls) were
  not being encoded when followed by valid protocol names, causing
  them to be dropped from the parsed multiaddr.

- Improve error messages to exclude invalid values
  Error messages for tag-only protocols now only show the protocol
  name and not the invalid value, making them clearer and more helpful.

Fixes the test failures where valid multiaddrs with tag-only protocols
followed by other protocols were incorrectly parsed.
Add explicit type annotation  to help pyrefly type checker
resolve type inference issues when idx is modified in nested loops.
Change idx += N to idx = idx + N in unix path handling to help
pyrefly 0.41.0 type checker resolve type inference issues in nested loops.
@acul71
Copy link
Contributor

acul71 commented Nov 11, 2025

@yashksaini-coder Thank you for this PR. please resolve the linting issues and failing test.
Also add documentation please (newsfragment and documentation example )

- Simplify unix path handling: use list comprehension instead of nested loop
  to avoid type inference issues with idx mutation
- Simplify flag-protocol lookahead: use direct idx assignment instead of
  idx = next_idx - 1; idx += 1 pattern
- Fix Makefile clean-build: use rm -rf instead of rm -f for .egg files
  to handle both files and directories

These changes resolve the pyrefly 'int is not assignable to int' error
caused by complex index mutation patterns confusing the type analyzer.
@yashksaini-coder
Copy link
Contributor Author

@acul71 Hi, seems you have made all failing ci checks passed. I really appreciate this. Anything else remaining on this PR, which we need to resolve, or can we do final review + merge

@acul71
Copy link
Contributor

acul71 commented Nov 11, 2025

Anything else remaining on this PR

newsfragment and documentation example

- Introduced a new section in the examples documentation for tag-only protocols, detailing their usage, validation, error handling, and integration with multiaddr addresses.
- Added a Python example file demonstrating these concepts.

This enhances the documentation by providing clear guidance on working with tag-only protocols.
- Updated the examples in `tag_only_examples.py` to improve address validation by using a placeholder variable for `Multiaddr` instantiation.
- Enhanced error handling messages to provide clearer feedback on invalid addresses.

These changes aim to streamline the usage examples and improve the overall clarity of error reporting for tag-only protocols.
@yashksaini-coder
Copy link
Contributor Author

Anything else remaining on this PR

newsfragment and documentation example

Done please have a review.

@seetadev
Copy link
Contributor

@yashksaini-coder : Ready for merge. Appreciate your support and efforts.

@seetadev seetadev merged commit efe9182 into multiformats:master Nov 12, 2025
17 checks passed
@yashksaini-coder yashksaini-coder deleted the Fix/98 branch November 12, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Tag-Only Protocols Accept Extra Value via = and Give Poor Error for /tag/value

3 participants