Skip to content

Commit

Permalink
Fixed path in url percent encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
amosavian committed Jan 16, 2017
1 parent 24355a4 commit 3aac0a8
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Sources/FileProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public protocol FileProviderBasic: class {
var delegate: FileProviderDelegate? { get set }
var credential: URLCredential? { get }

/**
*
*/
func contentsOfDirectory(path: String, completionHandler: @escaping ((_ contents: [FileObject], _ error: Error?) -> Void))
func attributesOfItem(path: String, completionHandler: @escaping ((_ attributes: FileObject?, _ error: Error?) -> Void))

Expand Down Expand Up @@ -194,30 +191,27 @@ extension FileProviderBasic {
}

func escaped(path: String) -> String {
return path.trimmingCharacters(in: pathTrimSet)
return path.trimmingCharacters(in: pathTrimSet).addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
}

public func absoluteURL(_ path: String? = nil) -> URL {
return url(of: path).absoluteURL
}

public func url(of path: String? = nil) -> URL {
let rpath: String
var rpath: String
if let path = path {
rpath = path
} else {
rpath = self.currentPath
}
if isPathRelative, let baseURL = baseURL {
if rpath.hasPrefix("/") && baseURL.absoluteString.hasSuffix("/") {
var npath = rpath
npath.remove(at: npath.startIndex)
return URL(string: npath, relativeTo: baseURL)!
} else {
return URL(string: rpath, relativeTo: baseURL)!
if rpath.hasPrefix("/") {
rpath.remove(at: rpath.startIndex)
}
return URL(string: rpath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!, relativeTo: baseURL)!
} else {
return URL(fileURLWithPath: rpath).standardizedFileURL
return URL(string: rpath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!)!.standardizedFileURL
}
}

Expand Down

0 comments on commit 3aac0a8

Please sign in to comment.