From 02c59d9967661a64ef9b3aad31198a2d265123ec Mon Sep 17 00:00:00 2001 From: Robin van Boven <497556+Beanow@users.noreply.github.com> Date: Fri, 10 Jan 2020 12:12:25 +0100 Subject: [PATCH] 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. --- src/plugins/discourse/references.js | 2 +- src/plugins/discourse/references.test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/plugins/discourse/references.js b/src/plugins/discourse/references.js index e8c3b4f..0ae1756 100644 --- a/src/plugins/discourse/references.js +++ b/src/plugins/discourse/references.js @@ -69,7 +69,7 @@ export function parseLinks(cookedHtml: string, serverUrl: string): UrlString[] { export function linksToReferences( links: $ReadOnlyArray ): DiscourseReference[] { - const server = "(https://[\\w.-]+)"; + const server = "(https?://[\\w.-]+)"; const topic = `(?:${server})/t/[\\w-]+/(\\d+)`; const post = `(?:${topic})/(\\d+)`; const params = "(?:\\?[\\w-=]+)?"; diff --git a/src/plugins/discourse/references.test.js b/src/plugins/discourse/references.test.js index 1166268..3bc345e 100644 --- a/src/plugins/discourse/references.test.js +++ b/src/plugins/discourse/references.test.js @@ -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",