Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ public final class AppNavigationRouteDecisionHandler: RouteDecisionHandler {
public func matches(proposal: VisitProposal,
configuration: Navigator.Configuration) -> Bool {
let location = proposal.url

/// Only HTTP(S) URLs can be routed in-app. A same-host URL with a custom
/// scheme (e.g. `webcal://my.app.com/calendar.ics`) must fall through to
/// `SystemNavigationRouteDecisionHandler` so the system can open it.
guard location.scheme == "http" || location.scheme == "https" else {
return false
}

if #available(iOS 16, *) {
return configuration.startLocation.host() == location.host()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public final class SystemNavigationRouteDecisionHandler: RouteDecisionHandler {
public func matches(proposal: VisitProposal,
configuration: Navigator.Configuration) -> Bool {
let location = proposal.url

/// Non-HTTP(S) URLs (webcal:, mailto:, sms:, ...) are always opened via
/// the system, even when they point at the app's own host.
guard location.scheme == "http" || location.scheme == "https" else {
return true
}

if #available(iOS 16, *) {
return configuration.startLocation.host() != location.host()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ final class AppNavigationRouteDecisionHandlerTest: XCTestCase {
XCTAssertFalse(result)
}

func test_non_http_scheme_on_app_domain_does_not_match() {
let url = URL(string: "webcal://my.app.com/calendars/subscribe.ics?token=123")!
let result = route.matches(proposal: proposal(for: url), configuration: navigatorConfiguration)

XCTAssertFalse(result)
}

func test_masqueraded_url_does_not_match() {
let url = URL(string: "https://app.my.com@fake.domain")!
let result = route.matches(proposal: proposal(for: url), configuration: navigatorConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ final class SystemNavigationRouteDecisionHandlerTests: XCTestCase {
XCTAssertTrue(result)
}

func test_non_http_scheme_on_app_domain_matches() {
let url = URL(string: "webcal://my.app.com/calendars/subscribe.ics?token=123")!
let result = route.matches(proposal: proposal(for: url), configuration: navigatorConfiguration)

XCTAssertTrue(result)
}

func test_sms_urls_match() {
let url = URL(string: "sms:1-408-555-1212")!
let result = route.matches(proposal: proposal(for: url), configuration: navigatorConfiguration)
Expand Down