Conversation
## Motivation and Context `Discovery.canonicalize_url` resolved dot segments with RFC 3986 Section 5.2.4 applied literally: every `.` or `..` rewrote the remaining input buffer, which copies it each time, so the cost grew with the square of the path's length. The path is the server's to choose, through a Protected Resource Metadata `resource` or an endpoint URL that reaches the canonicalization: resolving a 2 MB path made of `a/../` took over 30 seconds, on every flow that received it. The segments are now visited once with a stack, which is the same algorithm expressed over segments instead of over the buffer. The output is unchanged, including the RFC's handling of a trailing `/.` or `/..` (the slash stays) and of a relative path (which `URI#path` never yields), as checked against the previous implementation on 100,000 random paths. ## How Has This Been Tested? New tests in `test/mcp/client/oauth/discovery_test.rb` canonicalize a URL with 300,000 dot segments within a bound the previous implementation exceeded many times over, and pin the trailing-slash and empty-segment cases. ## Breaking Changes None.
koic
force-pushed
the
remove_dot_segments_in_linear_time
branch
from
September 24, 2026 15:36
5a1c362 to
5e2edae
Compare
atesgoral
approved these changes
Sep 24, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Discovery.canonicalize_urlresolved dot segments with RFC 3986 Section 5.2.4 applied literally: every.or..rewrote the remaining input buffer, which copies it each time, so the cost grew with the square of the path's length. The path is the server's to choose, through a Protected Resource Metadataresourceor an endpoint URL that reaches the canonicalization: resolving a 2 MB path made ofa/../took over 30 seconds, on every flow that received it.The segments are now visited once with a stack, which is the same algorithm expressed over segments instead of over the buffer. The output is unchanged, including the RFC's handling of a trailing
/.or/..(the slash stays) and of a relative path (whichURI#pathnever yields), as checked against the previous implementation on 100,000 random paths.How Has This Been Tested?
New tests in
test/mcp/client/oauth/discovery_test.rbcanonicalize a URL with 300,000 dot segments within a bound the previous implementation exceeded many times over, and pin the trailing-slash and empty-segment cases.Breaking Changes
None.
Types of changes
Checklist