27

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:

Linked in sidebar

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.

1
  • 10
    Well, that explains a lot of mild bewilderment I've had about the Linked Questions section lately…. Commented Feb 19, 2017 at 0:07

1 Answer 1

7

Relative URLs are now supported... But protocol-relative links aren't and likely won't be.

Turns out, protocol-relative links aren't exactly encouraged anymore - and they can cause issues if and when these posts are consumed in a different format or venue (such as email, or mobile apps, or whatever someone might want to do with the API). The canonical URL for questions is HTTPS and has been for a while - we rewrote all the links we could find during the migration and should probably disallow the use of both HTTP and protocol-relative links in posts going forward.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.