Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golink: strip trailing punctuation when resolving links #159

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

willnorris
Copy link
Member

It's not uncommon for auto-linkers or simple copy/paste errors to accidentally include trailing punctuation in a golink. When resolving links, if the initial link was not found, then try again with common punctuation (that is invalid in link names anyway) removed.

Fixes #148

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d

It's not uncommon for auto-linkers or simple copy/paste errors to
accidentally include trailing punctuation in a golink. When resolving
links, if the initial link was not found, then try again with common
punctuation (that is invalid in link names anyway) removed.

Fixes #148

Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d
Signed-off-by: Will Norris <[email protected]>
if errors.Is(err, fs.ErrNotExist) {
// Trim common punctuation from the end and try again.
// This catches auto-linking and copy/paste issues that include punctuation.
if s := strings.TrimRight(short, ".,()[]{}"); short != s {
Copy link
Member

Choose a reason for hiding this comment

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

Even though it's valid, it might be worth taking ? too, since such a URL's query is empty anyway at that point (the same argument could apply to ., since it's valid in paths). YMMV.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm... I tried adding ?, but turns out it's not really needed. Since this is based solely on the r.URL.Path value, it seems that the only way a question mark could appear is if it was url encoded as %3F. But then we never url-decode, so it wouldn't actually get stripped off. Since we're just trying to handle accidental punctuation, I don't think we need to worry about ?, since it would get stripped already by the URL parsing.

@willnorris willnorris merged commit c21529a into main Jan 10, 2025
4 checks passed
@willnorris willnorris deleted the will/punctuation branch January 10, 2025 22:24
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.

Ignore trailing dot
2 participants