Skip to content

Commit

Permalink
fix: 参数解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
林翰 committed Nov 22, 2017
1 parent 6b0e9af commit 1a00a46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion SPRoutable.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SPRoutable'
s.version = '0.7.5'
s.version = '0.7.6'
s.summary = '基础的路由服务'


Expand Down
29 changes: 16 additions & 13 deletions Sources/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public extension Routable {
let targetName = classPrefix + name
cache.removeValue(forKey: targetName)
}

public static func urlFormat(url: URLProtocol,params:[String: Any]) -> URL?{
if params.isEmpty { return url.asURL() }

guard var components = URLComponents(string: url.asString()) else { return nil }
var querys = components.queryItems ?? []

let newQuerys = params.map { (item) -> URLQueryItem in
let value = String(describing: item.value)
return URLQueryItem(name: item.key, value: value)
Expand All @@ -50,7 +50,7 @@ public extension Routable {
components.queryItems = querys
return components.url
}

/// 解析viewController类型
///
/// - Parameter url: viewController 路径
Expand Down Expand Up @@ -85,8 +85,8 @@ public extension Routable {
if let element = object as? T { return element }
return nil
}


/// 通知所有已缓存类型函数
///
/// - Parameter url: 函数路径
Expand All @@ -96,15 +96,15 @@ public extension Routable {
assert(false, "检查 URL host: " + (path.host ?? "") + "🌰: http://notice/path")
return
}

cache.keys.forEach({ (item) in
//TODO: 不太严谨
let name = item.replacingOccurrences(of: classPrefix, with: "")
let path = path.asString().replacingOccurrences(of: "://notice/", with: "://\(name)/")
Routable.executing(url: path,isAssert: false)
})
}


/// 执行路径指定函数
///
Expand Down Expand Up @@ -150,7 +150,7 @@ extension Routable {
let sel = NSSelectorFromString(funcPrefix + name + "With" + paramName + ":")
if target.responds(to: sel){ return sel }
}

do {
let sel = NSSelectorFromString(funcPrefix + name + paramName + ":")
if target.responds(to: sel){ return sel }
Expand All @@ -160,7 +160,7 @@ extension Routable {
let sel = NSSelectorFromString(funcPrefix + name + ":")
if target.responds(to: sel){ return sel }
}

return nil
}else{
let sel = NSSelectorFromString(funcPrefix + name)
Expand Down Expand Up @@ -210,12 +210,15 @@ extension Routable {
assert(false, "url格式不正确:" + url.absoluteString)
return nil
}

if let urlstr = url.query {
urlstr.components(separatedBy: "&").forEach { (item) in
let list = item.components(separatedBy: "=")
if list.count < 2 { return }
params[list.first!] = list.last!.removingPercentEncoding ?? ""
if list.count == 2 {
params[list.first!] = list.last!.removingPercentEncoding ?? ""
}else if list.count > 2 {
params[list.first!] = list.dropFirst().joined().removingPercentEncoding ?? ""
}
}
}

Expand Down

0 comments on commit 1a00a46

Please sign in to comment.