浏览代码

Fix crash decoding statuses sent from certain applications

If an application provides its URL as an empty string, decoding it would
cause throw an error because Foundation's URL class does not accept
empty strings. Instead, during parsing, consume the invalid URL and
replace it with a `nil` app URL.
multiple-accounts
Shadowfacts 1 个月前
父节点
当前提交
787dc9f24f
签署人:: Shadowfacts <me@shadowfacts.net> GPG 密钥 ID: 94A5AB95422746E5
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13
    0
      Pachyderm/Model/Application.swift

+ 13
- 0
Pachyderm/Model/Application.swift 查看文件

@@ -12,6 +12,19 @@ public class Application: Decodable {
12 12
     public let name: String
13 13
     public let website: URL?
14 14
     
15
+    public required init(from decoder: Decoder) throws {
16
+        let container = try decoder.container(keyedBy: CodingKeys.self)
17
+        
18
+        self.name = try container.decode(String.self, forKey: .name)
19
+        
20
+        if let websiteStr = try container.decodeIfPresent(String.self, forKey: .website),
21
+            let url = URL(string: websiteStr) {
22
+            self.website = url
23
+        } else {
24
+            self.website = nil
25
+        }
26
+    }
27
+    
15 28
     private enum CodingKeys: String, CodingKey {
16 29
         case name
17 30
         case website

正在加载...
取消
保存