Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
125 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
8 changes: 8 additions & 0 deletions
8
android/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.getcapacitor; | ||
|
||
/** | ||
* An interface used in the processing of routes | ||
*/ | ||
public interface RouteProcessor { | ||
String process(String path); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// Router.swift | ||
// Capacitor | ||
// | ||
// Created by Steven Sherry on 3/29/22. | ||
// Copyright © 2022 Drifty Co. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Router { | ||
func route(for path: String) -> String | ||
} | ||
|
||
// swiftlint:disable:next type_name | ||
internal struct _Router: Router { | ||
func route(for path: String) -> String { | ||
let pathUrl = URL(string: 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 { | ||
return "/index.html" | ||
} | ||
|
||
return path | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// RouterTests.swift | ||
// CapacitorTests | ||
// | ||
// Created by Steven Sherry on 3/29/22. | ||
// Copyright © 2022 Drifty Co. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Capacitor | ||
|
||
class RouterTests: XCTestCase { | ||
let router = _Router() | ||
|
||
func testRouterReturnsIndexWhenProvidedInvalidPath() { | ||
XCTAssertEqual(router.route(for: "/skull.💀"), "/index.html") | ||
} | ||
|
||
func testRouterReturnsIndexWhenProvidedEmptyPath() { | ||
XCTAssertEqual(router.route(for: ""), "/index.html") | ||
} | ||
|
||
func testRouterReturnsIndexWhenProviedPathWithoutExtension() { | ||
XCTAssertEqual(router.route(for: "/a/valid/path/no/ext"), "/index.html") | ||
} | ||
|
||
func testRouterReturnsPathWhenProvidedValidPath() { | ||
XCTAssertEqual(router.route(for: "/a/valid/path.ext"), "/a/valid/path.ext") | ||
} | ||
} |