Fix: support HTTP references on Discourse (#1529)

Note, adding support in this single function doesn't solve some of the greater issues with HTTP/HTTPS. Because the protocol is included in the node addresses, converging nodes or canonicalizing on either protocol would be important for instances that support HTTP. That problem is outside of scope for the reference detector though.
This commit is contained in:
Robin van Boven 2020-01-10 12:12:25 +01:00 committed by GitHub
parent 4d77516bf4
commit 02c59d9967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -69,7 +69,7 @@ export function parseLinks(cookedHtml: string, serverUrl: string): UrlString[] {
export function linksToReferences(
links: $ReadOnlyArray<UrlString>
): DiscourseReference[] {
const server = "(https://[\\w.-]+)";
const server = "(https?://[\\w.-]+)";
const topic = `(?:${server})/t/[\\w-]+/(\\d+)`;
const post = `(?:${topic})/(\\d+)`;
const params = "(?:\\?[\\w-=]+)?";

View File

@ -50,6 +50,24 @@ describe("plugins/discourse/references", () => {
});
describe("linksToReferences", () => {
it("works for http and https servers", () => {
const hyperlinks = [
"http://sourcecred-test.discourse.group/t/123-a-post-with-numbers-in-slug/20",
"https://sourcecred-test.discourse.group/t/123-a-post-with-numbers-in-slug/20",
];
expect(linksToReferences(hyperlinks)).toEqual([
{
type: "TOPIC",
topicId: 20,
serverUrl: "http://sourcecred-test.discourse.group",
},
{
type: "TOPIC",
topicId: 20,
serverUrl: "https://sourcecred-test.discourse.group",
},
]);
});
it("works for topics", () => {
const hyperlinks = [
"https://sourcecred-test.discourse.group/t/123-a-post-with-numbers-in-slug/20",