Przeglądaj źródła

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 miesiąc temu
rodzic
commit
787dc9f24f
Podpisane przez: Shadowfacts <me@shadowfacts.net> ID klucza GPG: 94A5AB95422746E5
1 zmienionych plików z 13 dodań i 0 usunięć
  1. 13
    0
      Pachyderm/Model/Application.swift

+ 13
- 0
Pachyderm/Model/Application.swift Wyświetl plik

@@ -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

Ładowanie…
Anuluj
Zapisz