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:
parent
4d77516bf4
commit
02c59d9967
|
@ -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-=]+)?";
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue