Skip to content

Conversation

d-ronnqvist
Copy link
Contributor

Bug/issue #, if applicable: rdar://162860967

Summary

This uses simpler string trimming instead of full URL parsing to trim a known prefix from a reference string.

Doing so avoids a crash when the written link has two or more slashes after the identifier (corresponding to a host component in a URL.

Dependencies

None.

Testing

See #1320 but include <doc://com.test.bundle//path/to/something> (with two slashes after the identifier).

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • [ ] Updated documentation if necessary

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist requested a review from anferbui October 21, 2025 09:11
Copy link
Contributor

@anferbui anferbui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with minor comment

let linkString = unresolvedReference.topicURL.url.withoutHostAndPortAndScheme().standardized.absoluteString
let linkString = String(
unresolvedReferenceString.dropFirst(6) // "doc://"
.drop(while: { $0 != "/" }) // the known identifier (host component)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we know the bundle ID, should we drop that instead of dropping until the first /?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way works. I don't have a strong opinion on how to implement. IMO the current implementation is fine, isn't externally visible, and is covered by tests so we can always change it in the future if we feel a need.

@d-ronnqvist d-ronnqvist merged commit 55fbcce into swiftlang:main Oct 21, 2025
2 checks passed
@d-ronnqvist d-ronnqvist deleted the avoid-url-parsing-when-trimming-known-prefix branch October 21, 2025 09:49
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.

2 participants