From 857f0865010284d7179c0a1c462050d2cf7f1391 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 3 Dec 2019 00:05:19 +0000 Subject: [PATCH 1/2] Fix ?via= args in SpecPermalinkConstructor.js Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils/permalinks/SpecPermalinkConstructor.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/utils/permalinks/SpecPermalinkConstructor.js b/src/utils/permalinks/SpecPermalinkConstructor.js index 1c80ff8975..d8b3633bb3 100644 --- a/src/utils/permalinks/SpecPermalinkConstructor.js +++ b/src/utils/permalinks/SpecPermalinkConstructor.js @@ -73,18 +73,16 @@ export default class SpecPermalinkConstructor extends PermalinkConstructor { // Probably a group, no further parsing needed. return PermalinkParts.forGroup(entity); } else if (entity[0] === '#' || entity[0] === '!') { - if (parts.length === 1) { - return PermalinkParts.forRoom(entity, []); + if (parts.length === 1) { // room without event permalink + const [roomId, query=""] = entity.split("?"); + const via = query.split(/&?via=/g).filter(p => !!p); + return PermalinkParts.forRoom(roomId, via); } // rejoin the rest because v3 events can have slashes (annoyingly) const eventIdAndQuery = parts.length > 1 ? parts.slice(1).join('/') : ""; - const secondaryParts = eventIdAndQuery.split("?"); - - const eventId = secondaryParts[0]; - const query = secondaryParts.length > 1 ? secondaryParts[1] : ""; - - const via = query.split("via=").filter(p => !!p); + const [eventId, query=""] = eventIdAndQuery.split("?"); + const via = query.split(/&?via=/g).filter(p => !!p); return PermalinkParts.forEvent(entity, eventId, via); } else { From a63fbbf2db57e7d4df0f396c3f1d01fca1eeb800 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 5 Dec 2019 00:11:10 +0000 Subject: [PATCH 2/2] Add tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- test/utils/permalinks/Permalinks-test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/utils/permalinks/Permalinks-test.js b/test/utils/permalinks/Permalinks-test.js index 27f06b44cb..32a42a7728 100644 --- a/test/utils/permalinks/Permalinks-test.js +++ b/test/utils/permalinks/Permalinks-test.js @@ -19,6 +19,7 @@ import { makeGroupPermalink, makeRoomPermalink, makeUserPermalink, + parsePermalink, RoomPermalinkCreator, } from "../../../src/utils/permalinks/Permalinks"; import * as testUtils from "../../test-utils"; @@ -450,4 +451,24 @@ describe('Permalinks', function() { const result = makeGroupPermalink("+community:example.org"); expect(result).toBe("https://matrix.to/#/+community:example.org"); }); + + it('should correctly parse room permalinks with a via argument', () => { + const result = parsePermalink("https://matrix.to/#/!room_id:server?via=some.org"); + expect(result.roomIdOrAlias).toBe("!room_id:server"); + expect(result.viaServers).toEqual(["some.org"]); + }); + + it('should correctly parse room permalink via arguments', () => { + const result = parsePermalink("https://matrix.to/#/!room_id:server?via=foo.bar&via=bar.foo"); + expect(result.roomIdOrAlias).toBe("!room_id:server"); + expect(result.viaServers).toEqual(["foo.bar", "bar.foo"]); + }); + + it('should correctly parse event permalink via arguments', () => { + const result = parsePermalink("https://matrix.to/#/!room_id:server/$event_id/some_thing_here/foobar" + + "?via=m1.org&via=m2.org"); + expect(result.eventId).toBe("$event_id/some_thing_here/foobar"); + expect(result.roomIdOrAlias).toBe("!room_id:server"); + expect(result.viaServers).toEqual(["m1.org", "m2.org"]); + }); });