Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): Use URL(fileURLWithPath:) instead of URL(string:) #5603

Merged
merged 2 commits into from
May 10, 2022
Merged
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
6 changes: 3 additions & 3 deletions ios/Capacitor/Capacitor/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public protocol Router {
// swiftlint:disable:next type_name
internal struct _Router: Router {
func route(for path: String) -> String {
let pathUrl = URL(string: path)
let pathUrl = URL(fileURLWithPath: path)

// if the pathUrl is null, then it is an invalid url (meaning it is empty or just plain invalid) then we want to route to /index.html
if pathUrl?.pathExtension.isEmpty ?? true {
// If there's no path extension it also means the path is empty or a SPA route
if pathUrl.pathExtension.isEmpty {
return "/index.html"
}

Expand Down
8 changes: 4 additions & 4 deletions ios/Capacitor/CapacitorTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import XCTest
class RouterTests: XCTestCase {
let router = _Router()

func testRouterReturnsIndexWhenProvidedInvalidPath() {
XCTAssertEqual(router.route(for: "/skull.💀"), "/index.html")
}

func testRouterReturnsIndexWhenProvidedEmptyPath() {
XCTAssertEqual(router.route(for: ""), "/index.html")
}
Expand All @@ -27,4 +23,8 @@ class RouterTests: XCTestCase {
func testRouterReturnsPathWhenProvidedValidPath() {
XCTAssertEqual(router.route(for: "/a/valid/path.ext"), "/a/valid/path.ext")
}

func testRouterReturnsPathWhenProvidedValidPathWithExtensionAndSpaces() {
XCTAssertEqual(router.route(for: "/a/valid/file path.ext"), "/a/valid/file path.ext")
}
}