Skip to content

Commit

Permalink
fix: fixed bug that prevents loading documents with spaces in name. A…
Browse files Browse the repository at this point in the history
…dded new error for file without extension
  • Loading branch information
nflsilva committed Mar 29, 2022
1 parent 14b2666 commit 3eb13ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ios/FileViewerErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum FileViewerErrors: String, Error {
case invalidURL = "The URL you are trying to open is malformed"
case invalidEmptyURL = "Path of the file to open is either null or empty"
case downloadFailed = "The download failed"
case missingFileExtension = "The file has no extension"
}

extension FileViewerErrors : LocalizedError {
Expand Down
6 changes: 5 additions & 1 deletion src/ios/FileViewerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class FileViewerPlugin {

if let url = urlString {
if let file = URL.init(string: url) {

let fileName = file.lastPathComponent
guard fileName.contains(".") else { throw FileViewerErrors.missingFileExtension }

guard FileManager.default.fileExists(atPath: file.path) else { throw FileViewerErrors.fileDoesNotExist }

if let viewController = rootViewController {
Expand All @@ -40,7 +44,7 @@ class FileViewerPlugin {
return completion({ throw FileViewerErrors.invalidURL })
}

if let fileUrl = URL(string: url), let viewController = rootViewController {
if let fileUrl = URL(string: url.replacingOccurrences(of: " ", with: "%20")), let viewController = rootViewController {
let fileViewerOpenDocument = FileViewerOpenDocument(viewController: viewController)
fileViewerOpenDocument.openDocumentFromUrl(url:fileUrl, completion: { (inner: ErrorCompletionHandler) -> Void in
do {
Expand Down

0 comments on commit 3eb13ea

Please sign in to comment.