Fixed a bug where the OpenGroup url parsing wasn't working for a certain URL structure

This commit is contained in:
Morgan Pretty 2022-03-18 10:20:59 +11:00
parent d3e9fff893
commit 452614d190
1 changed files with 4 additions and 1 deletions

View File

@ -126,7 +126,10 @@ public final class OpenGroupManagerV2 : NSObject {
// https://143.198.213.225:443/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c
// 143.198.213.255:80/main?public_key=658d29b91892a2389505596b135e76a53db6e11d613a51dbd3d0816adffb231c
let useTLS = (url.scheme == "https")
let updatedPath = (url.path.starts(with: "/r/") ? url.path.substring(from: 2) : url.path)
// If there is no scheme then the host is included in the path (so handle that case)
let hostFreePath = (url.host != nil || !url.path.starts(with: host) ? url.path : url.path.substring(from: host.count))
let updatedPath = (hostFreePath.starts(with: "/r/") ? hostFreePath.substring(from: 2) : hostFreePath)
let room = String(updatedPath.dropFirst()) // Drop the leading slash
let queryParts = query.split(separator: "=")
guard !room.isEmpty && !room.contains("/"), queryParts.count == 2, queryParts[0] == "public_key" else { return nil }