Skip to content

Commit 1a00a46

Browse files
author
林翰
committed
fix: 参数解析错误
1 parent 6b0e9af commit 1a00a46

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

SPRoutable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SPRoutable'
3-
s.version = '0.7.5'
3+
s.version = '0.7.6'
44
s.summary = '基础的路由服务'
55

66

Sources/Routable.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public extension Routable {
3535
let targetName = classPrefix + name
3636
cache.removeValue(forKey: targetName)
3737
}
38-
38+
3939
public static func urlFormat(url: URLProtocol,params:[String: Any]) -> URL?{
4040
if params.isEmpty { return url.asURL() }
41-
41+
4242
guard var components = URLComponents(string: url.asString()) else { return nil }
4343
var querys = components.queryItems ?? []
44-
44+
4545
let newQuerys = params.map { (item) -> URLQueryItem in
4646
let value = String(describing: item.value)
4747
return URLQueryItem(name: item.key, value: value)
@@ -50,7 +50,7 @@ public extension Routable {
5050
components.queryItems = querys
5151
return components.url
5252
}
53-
53+
5454
/// 解析viewController类型
5555
///
5656
/// - Parameter url: viewController 路径
@@ -85,8 +85,8 @@ public extension Routable {
8585
if let element = object as? T { return element }
8686
return nil
8787
}
88-
89-
88+
89+
9090
/// 通知所有已缓存类型函数
9191
///
9292
/// - Parameter url: 函数路径
@@ -96,15 +96,15 @@ public extension Routable {
9696
assert(false, "检查 URL host: " + (path.host ?? "") + "🌰: http://notice/path")
9797
return
9898
}
99-
99+
100100
cache.keys.forEach({ (item) in
101101
//TODO: 不太严谨
102102
let name = item.replacingOccurrences(of: classPrefix, with: "")
103103
let path = path.asString().replacingOccurrences(of: "://notice/", with: "://\(name)/")
104104
Routable.executing(url: path,isAssert: false)
105105
})
106106
}
107-
107+
108108

109109
/// 执行路径指定函数
110110
///
@@ -150,7 +150,7 @@ extension Routable {
150150
let sel = NSSelectorFromString(funcPrefix + name + "With" + paramName + ":")
151151
if target.responds(to: sel){ return sel }
152152
}
153-
153+
154154
do {
155155
let sel = NSSelectorFromString(funcPrefix + name + paramName + ":")
156156
if target.responds(to: sel){ return sel }
@@ -160,7 +160,7 @@ extension Routable {
160160
let sel = NSSelectorFromString(funcPrefix + name + ":")
161161
if target.responds(to: sel){ return sel }
162162
}
163-
163+
164164
return nil
165165
}else{
166166
let sel = NSSelectorFromString(funcPrefix + name)
@@ -210,12 +210,15 @@ extension Routable {
210210
assert(false, "url格式不正确:" + url.absoluteString)
211211
return nil
212212
}
213-
213+
214214
if let urlstr = url.query {
215215
urlstr.components(separatedBy: "&").forEach { (item) in
216216
let list = item.components(separatedBy: "=")
217-
if list.count < 2 { return }
218-
params[list.first!] = list.last!.removingPercentEncoding ?? ""
217+
if list.count == 2 {
218+
params[list.first!] = list.last!.removingPercentEncoding ?? ""
219+
}else if list.count > 2 {
220+
params[list.first!] = list.dropFirst().joined().removingPercentEncoding ?? ""
221+
}
219222
}
220223
}
221224

0 commit comments

Comments
 (0)