Ignore file URLs in DeepLinkRouter#106
Draft
wojt-janowski wants to merge 1 commit intoNativePHP:mainfrom
Draft
Conversation
When an iOS app declares CFBundleDocumentTypes (or LSSupportsOpeningDocumentsInPlace) so it can receive shared files from other apps' share sheets / "Open In…", iOS delivers a `file://` URL through the standard URL handlers (AppDelegate.application(_:open:options:) and SwiftUI's WindowGroup .onOpenURL). Both call sites currently forward unconditionally to DeepLinkRouter.shared.handle(url:), which strips the scheme and treats the absolute file path as a Laravel route. The user sees: The route /private/var/mobile/Containers/.../Inbox/scan.pdf could not be found. DeepLinkRouter has no business handling file URLs — it only knows about custom URL schemes and universal links. Plugins that declare document types are responsible for handling inbound file URLs before they reach the router. Add a guard so file URLs are ignored (with a debug log) instead of mangled into bad routes. This eliminates the need for plugins like share-target receivers to runtime-patch AppDelegate.swift and NativePHPApp.swift just to short- circuit file URLs around DeepLinkRouter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DeepLinkRouter.handle(url:)againstfile://URLs so plugins that declare document types don't have to runtime-patchAppDelegate.swift/NativePHPApp.swiftto keep their inbound files away from the deep-link router.The route /private/var/mobile/Containers/.../Inbox/scan.pdf could not be found.Why
Apps that register
CFBundleDocumentTypes(andLSSupportsOpeningDocumentsInPlace) — for example, a PDF viewer, an image importer, or a share-target receiver — receivefile://URLs from iOS through the same code paths as deep links:AppDelegate.application(_:didFinishLaunchingWithOptions:)reads theURLfromlaunchOptionsand forwards it toDeepLinkRouter.shared.handle(url:).AppDelegate.application(_:open:options:)forwards toDeepLinkRouter.shared.handle(url:).WindowGroup's.onOpenURLinNativePHPApp.swiftforwards toDeepLinkRouter.shared.handle(url:).DeepLinkRouter.handle(url:)then enters the custom-scheme branch (sinceurl.scheme == "file"is neitherhttpnorhttps), normalises the file path intophp://127.0.0.1/private/var/mobile/.../filename.pdf, and asks Inertia to navigate there. The WebView 404s.The router is conceptually only for deep links — custom URL schemes registered via
CFBundleURLTypesand universal links via Associated Domains. File URLs are a different OS-level concept and belong to whichever plugin/listener declared the document type.Repro
CFBundleDocumentTypesentry to your NativePHP iOS app forcom.adobe.pdf, setLSSupportsOpeningDocumentsInPlace=true./private/var/mobile/.../filename.pdfand shows a Laravel 404.Fix
Add a
guard !url.isFileURL else { return }at the top ofDeepLinkRouter.handle(url:). The router logs and returns; downstream plugin handlers (e.g. those wired viaAppDelegate's open-URL methods or SwiftUI's.onOpenURL) are now free to handle the file URL.Alternatives considered
http,https, configuredNATIVEPHP_DEEPLINK_SCHEME) — more defensive but enumerates state already implicit inCFBundleURLTypesand would need plumbing to read the configured scheme into Swift. Felt like premature scope.DeepLinkRouter— adds new public API surface for a single-line bug fix.OpenFileRouter— same objection as above.The guard is the smallest change consistent with the file's existing shape (input normalization at the top of
handle, debug-logged early returns).Test plan
CFBundleDocumentTypesregistered → no more 404, plugin's file handler runs as expected.myapp://somethingdeep link → routes correctly (existing behaviour unchanged).myapp://somethingdeep link → routes correctly (existing behaviour unchanged).https://app.example.com/path) handled correctly (existing behaviour unchanged).Notes
Filing as draft for visibility / discussion. Happy to switch to the allowlist approach if maintainers prefer that over the targeted file-URL guard.