Преглед изворни кода

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
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key 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

Loading…
Откажи
Сачувај