@@ -117,7 +117,7 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
117117 let siteID = try siteContainer. decode ( Int64 . self, forKey: . siteID)
118118 let name = try siteContainer. decode ( String . self, forKey: . name)
119119 let description = try siteContainer. decode ( String . self, forKey: . description)
120- let url = try siteContainer. decode ( String . self, forKey: . url)
120+ let url = Self . safeURL ( try siteContainer. decode ( String . self, forKey: . url) )
121121 let capabilitiesContainer = try siteContainer. nestedContainer ( keyedBy: CapabilitiesKeys . self, forKey: . capabilities)
122122 let isSiteOwner = try capabilitiesContainer. decode ( Bool . self, forKey: . isSiteOwner)
123123 let isAdmin = try capabilitiesContainer. decode ( Bool . self, forKey: . isAdmin)
@@ -130,8 +130,8 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
130130 let jetpackConnectionActivePlugins = try optionsContainer. decodeIfPresent ( [ String ] . self, forKey: . jetpackConnectionActivePlugins) ?? [ ]
131131 let timezone = try optionsContainer. decode ( String . self, forKey: . timezone)
132132 let gmtOffset = try optionsContainer. decode ( Double . self, forKey: . gmtOffset)
133- let adminURL = try optionsContainer. decode ( String . self, forKey: . adminURL)
134- let loginURL = try optionsContainer. decode ( String . self, forKey: . loginURL)
133+ let adminURL = Self . safeURL ( try optionsContainer. decode ( String . self, forKey: . adminURL) )
134+ let loginURL = Self . safeURL ( try optionsContainer. decode ( String . self, forKey: . loginURL) )
135135 let frameNonce = try optionsContainer. decode ( String . self, forKey: . frameNonce)
136136 let canBlaze = optionsContainer. failsafeDecodeIfPresent ( booleanForKey: . canBlaze) ?? false
137137 let visibility = optionsContainer. failsafeDecodeIfPresent ( SiteVisibility . self, forKey: . visibility) ?? . privateSite
@@ -333,7 +333,8 @@ public enum SiteVisibility: Int, Codable, GeneratedFakeable {
333333///
334334public extension Site {
335335
336- private var jetpackCanonicalURL : String {
336+ /// Force URL to use HTTPS if possible to avoid App Transport Security errors
337+ private static func safeURL( _ url: String ) -> String {
337338 guard let originalURL = URL ( string: url) ,
338339 originalURL. scheme? . lowercased ( ) == " http "
339340 else {
@@ -360,7 +361,7 @@ public extension Site {
360361 }
361362
362363 func toJetpackSite( ) -> JetpackSite {
363- JetpackSite ( siteID: siteID, siteAddress: jetpackCanonicalURL , applicationPasswordAvailable: applicationPasswordAvailable)
364+ JetpackSite ( siteID: siteID, siteAddress: url , applicationPasswordAvailable: applicationPasswordAvailable)
364365 }
365366}
366367
0 commit comments