Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.1

### Fixes

- Remove duplicate path separators that could cause files to not be found.

## 1.0.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion IONFileViewerLib.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'IONFileViewerLib'
spec.version = '1.0.0'
spec.version = '1.0.1'

spec.summary = 'Library for viewing files in iOS.'
spec.description = <<-DESC
Expand Down
24 changes: 20 additions & 4 deletions IONFileViewerLib/IONFLVWManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ extension IONFLVWManager: IONFLVWOpenDocumentManager {
guard !filePath.isEmpty else {
throw IONFLVWError.emptyFilePath
}
guard let file = URL(string: filePath) else { throw IONFLVWError.couldNotOpenDocument }
let filePathToUse = replaceDuplicateSlashes(fromLocalPath: filePath)
guard let file = URL(string: filePathToUse) else { throw IONFLVWError.couldNotOpenDocument }
guard !file.pathExtension.isEmpty else { throw IONFLVWError.missingFileExtension }
guard fileManager.fileExists(atPath: file.path) else { throw IONFLVWError.fileDoesNotExist(atPath: filePath) }
guard fileManager.fileExists(atPath: file.path) else { throw IONFLVWError.fileDoesNotExist(atPath: filePathToUse) }

openDocumentFromLocalPath(file, completion)
}
Expand Down Expand Up @@ -59,8 +60,9 @@ extension IONFLVWManager: IONFLVWOpenDocumentManager {
extension IONFLVWManager: IONFLVWPreviewMediaManager {
public func previewMediaContentFromLocalPath(filePath: String) throws {
guard !filePath.isEmpty else { throw IONFLVWError.emptyFilePath }
guard let file = URL(string: filePath) else { throw IONFLVWError.couldNotOpenDocument }
guard fileManager.fileExists(atPath: file.path) else { throw IONFLVWError.fileDoesNotExist(atPath: filePath) }
let filePathToUse = replaceDuplicateSlashes(fromLocalPath: filePath)
guard let file = URL(string: filePathToUse) else { throw IONFLVWError.couldNotOpenDocument }
guard fileManager.fileExists(atPath: file.path) else { throw IONFLVWError.fileDoesNotExist(atPath: filePathToUse) }

previewMediaContent(file)
}
Expand Down Expand Up @@ -104,4 +106,18 @@ private extension IONFLVWManager {
let resourceURL = URL(fileURLWithPath: resourcePath)
return resourceURL
}

func replaceDuplicateSlashes(fromLocalPath path: String) -> String {
// remove duplicate slashes '//', except for the ones indicating the scheme (e.g. 'file://')
var pathWithoutDuplicateSeparators = path.replacingOccurrences(
of: #"(?<!:)/{2,}(?!/)"#,
with: "/",
options: .regularExpression
)
if (path.contains(":///")) {
// the regex may ommit a slash after ://, which is incorrect because it breaks in case of an absolute file path
pathWithoutDuplicateSeparators = pathWithoutDuplicateSeparators.replacingOccurrences(of: "://", with: ":///")
}
return pathWithoutDuplicateSeparators
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The library supports local files, app assets, and remote URLs.
`ion-ios-fileviewer` is available through [CocoaPods](https://cocoapods.org). Add this to your Podfile:

```ruby
pod 'IONFileViewerLib', '~> 1.0.0' # Use the latest 1.0.x version
pod 'IONFileViewerLib', '~> 1.0.1' # Use the latest 1.0.x version
```

## Quick Start
Expand Down
Loading