Currently, neither protocol-relative URLs, nor relative URLs, are recognized by the system as pointing to questions to be added to the "Linked" list for the current question. Given the pending switch to using HTTPS on Stack Overflow, and later on the entire Stack Exchange network, we should, at least, recognize protocol-relative links to questions as "Linked".
Investigation
I entered the following links into a comment to point to a potential duplicate1:
[Is there a JavaScript/jQuery DOM change listener?](//stackoverflow.com/q/2844565)
[Is there a JavaScript/jQuery DOM change listener?](//stackoverflow.com/questions/2844565)
[Is there a JavaScript/jQuery DOM change listener?](/q/2844565)
[Is there a JavaScript/jQuery DOM change listener?](/questions/2844565)
All of the above resulted in valid links to the question. None of these were picked up by the system to be considered as "Linked". By "Linked", I mean that the sidebar shows a "Linked" heading. What I expected to see was:
In order to get the question to show up as "Linked", I had to use a fully qualified URL:
[Is there a JavaScript/jQuery DOM change listener?](http://stackoverflow.com/q/2844565)
The code
We know from Shog9's answer that the code responsible for identifying "Linked" questions is:
public static Regex GetQuestionUrlRegex()
{
return new Regex(@"https?://" + Regex.Escape(Current.Site.BaseHostAddress) + @"(?:/q(uestions)?/(?<qid>\d+)|/a/(?<aid>\d+))", RegexOptions.IgnoreCase);
}
It seams that the Regex
could be changed to something like (untested):
public static Regex GetQuestionUrlRegex()
{
return new Regex(@"(?:https?:)?(?://" + Regex.Escape(Current.Site.BaseHostAddress) + @")?(?:/q(uestions)?/(?<qid>\d+)|/a/(?<aid>\d+))", RegexOptions.IgnoreCase);
}
This change would allow the recognition of fully qualified links, protocol-relative links, and relative links.
A potential issue is that I don't know what text is being checked by this generated Regex
. If this regular expression is being used to check the entirety of the raw HTML, then allowing it to pick up such shortened URLs may not be appropriate. If it is only testing active links, then it is reasonable to recognize the shorter, valid, URLs.
Notes:
- A bug report in 2012 regarding only relative links was declined at that time.
- I'm unsure if this post should be considered a bug report or a feature request. I consider it a bug. However, given the previously declined bug report, the current functionality could reasonably be considered a misfeature. In such case, this would then be a feature request.
1. I'm currently out of close votes, so was unable to vote to close the question.