Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 9ff448f

Browse files
committed
Fix encoding for some XMLRPC parameters
1 parent d25e7f9 commit 9ff448f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Sources/WordPressKit/Models/RemotePostParameters.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public struct RemotePostUpdateParameters: Equatable {
3535
public var ifNotModifiedSince: Date?
3636

3737
public var status: String?
38-
public var date: Date??
39-
public var authorID: Int??
38+
public var date: Date?
39+
public var authorID: Int?
4040
public var title: String??
4141
public var content: String??
4242
public var password: String??
@@ -393,14 +393,14 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
393393
func encode(to encoder: Encoder) throws {
394394
var container = encoder.container(keyedBy: RemotePostXMLRPCCodingKeys.self)
395395
try container.encodeIfPresent(parameters.ifNotModifiedSince, forKey: .ifNotModifiedSince)
396-
try container.encodeIfPresent(parameters.status, forKey: .postStatus)
396+
try container.encodeStringIfPresent(parameters.status, forKey: .postStatus)
397397
try container.encodeIfPresent(parameters.date, forKey: .date)
398398
try container.encodeIfPresent(parameters.authorID, forKey: .authorID)
399-
try container.encodeIfPresent(parameters.title, forKey: .title)
400-
try container.encodeIfPresent(parameters.content, forKey: .content)
401-
try container.encodeIfPresent(parameters.password, forKey: .password)
402-
try container.encodeIfPresent(parameters.excerpt, forKey: .excerpt)
403-
try container.encodeIfPresent(parameters.slug, forKey: .slug)
399+
try container.encodeStringIfPresent(parameters.title, forKey: .title)
400+
try container.encodeStringIfPresent(parameters.content, forKey: .content)
401+
try container.encodeStringIfPresent(parameters.password, forKey: .password)
402+
try container.encodeStringIfPresent(parameters.excerpt, forKey: .excerpt)
403+
try container.encodeStringIfPresent(parameters.slug, forKey: .slug)
404404
if let value = parameters.featuredImageID {
405405
if let featuredImageID = value {
406406
try container.encode(featuredImageID, forKey: .featuredImageID)
@@ -420,7 +420,7 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
420420
}
421421

422422
// Posts
423-
try container.encodeIfPresent(parameters.format, forKey: .format)
423+
try container.encodeStringIfPresent(parameters.format, forKey: .format)
424424
if let tags = parameters.tags {
425425
try container.encode(tags, forKey: .tags)
426426
}
@@ -440,3 +440,10 @@ struct RemotePostUpdateParametersXMLRPCMetadata: Encodable {
440440
self.value = item.value
441441
}
442442
}
443+
444+
private extension KeyedEncodingContainer {
445+
mutating func encodeStringIfPresent(_ value: String??, forKey key: Key) throws {
446+
guard let value else { return }
447+
try encode(value ?? "", forKey: key)
448+
}
449+
}

0 commit comments

Comments
 (0)