浏览代码

coding

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 年之前
父节点
当前提交
ed0ce0b8cc

+ 3 - 2
Widget/Nextcloud/NextcloudData.swift

@@ -200,9 +200,10 @@ func getDataEntry(completion: @escaping (_ entry: NextcloudDataEntry) -> Void) {
 
 
                 // Example: nextcloud://open-file?path=Talk/IMG_0000123.jpg&user=marinofaggiana&link=https://cloud.nextcloud.com/f/123
                 // Example: nextcloud://open-file?path=Talk/IMG_0000123.jpg&user=marinofaggiana&link=https://cloud.nextcloud.com/f/123
 
 
-                let path = NCUtilityFileSystem.shared.getPath(path: file.path, user: file.user, fileName: file.fileName)
+                guard let path = NCUtilityFileSystem.shared.getPath(path: file.path, user: file.user, fileName: file.fileName).urlEncoded else { continue }
+                guard let user = file.user.urlEncoded else { continue }
                 let link = file.urlBase + "/f/" + file.fileId
                 let link = file.urlBase + "/f/" + file.fileId
-                let urlString = "nextcloud://open-file?path=" + path + "&user=" + file.user + "&link=" + link
+                let urlString = "nextcloud://open-file?path=\(path)&user=\(user)&link=\(link)"
                 guard let url = URL(string: urlString) else { continue }
                 guard let url = URL(string: urlString) else { continue }
                 let recentData = RecentData.init(id: file.ocId, image: iconImagePath, title: file.fileName, subTitle: subTitle, url: url)
                 let recentData = RecentData.init(id: file.ocId, image: iconImagePath, title: file.fileName, subTitle: subTitle, url: url)
                 recentDatas.append(recentData)
                 recentDatas.append(recentData)

+ 1 - 1
Widget/Nextcloud/NextcloudWidgetView.swift

@@ -66,7 +66,7 @@ struct NextcloudWidgetView: View {
                     }
                     }
                 }
                 }
             }
             }
-            .padding(.top, 50)
+            .padding(.top, 45)
             .redacted(reason: entry.isPlaceholder ? .placeholder : [])
             .redacted(reason: entry.isPlaceholder ? .placeholder : [])
             Text(entry.footerText)
             Text(entry.footerText)
                 .font(.caption2)
                 .font(.caption2)

+ 7 - 0
iOSClient/Extensions/String+Extensions.swift

@@ -69,6 +69,13 @@ extension String {
 
 
         return digestData.map { String(format: "%02hhx", $0) }.joined()
         return digestData.map { String(format: "%02hhx", $0) }.joined()
     }
     }
+
+    var urlEncoded: String? {
+        // +        for historical reason, most web servers treat + as a replacement of whitespace
+        // ?, &     mark query pararmeter which should not be part of a url string, but added seperately
+        let urlAllowedCharSet = CharacterSet.urlQueryAllowed.subtracting(["+", "?", "&"])
+        return addingPercentEncoding(withAllowedCharacters: urlAllowedCharSet)
+    }
 }
 }
 
 
 extension StringProtocol {
 extension StringProtocol {