Skip to content

Commit 242e50f

Browse files
authored
Normalize remote post site IDs (#25773)
* Normalize remote post site IDs * Add a release note * Test numeric remote post site IDs
1 parent ec48f1f commit 242e50f

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

Modules/Sources/WordPressKitObjC/PostServiceRemoteREST.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import "RemotePostTerm.h"
55
#import "FilePart.h"
66
#import "NSString+Helpers.h"
7+
#import "NSString+WPKitNumericValueHack.h"
78

89
@import WordPressShared;
910
@import WordPressKitModels;
@@ -396,7 +397,8 @@ - (RemotePost *)remotePostFromJSONDictionary:(NSDictionary *)jsonPost {
396397
+ (RemotePost *)remotePostFromJSONDictionary:(NSDictionary *)jsonPost {
397398
RemotePost *post = [RemotePost new];
398399
post.postID = jsonPost[@"ID"];
399-
post.siteID = jsonPost[@"site_ID"];
400+
// Create and update responses return site_ID as a string, while read responses return a number.
401+
post.siteID = [jsonPost[@"site_ID"] wpkit_numericValue];
400402
if (jsonPost[@"author"] != [NSNull null]) {
401403
NSDictionary *authorDictionary = jsonPost[@"author"];
402404
post.authorAvatarURL = authorDictionary[@"avatar_URL"];

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* [*] [internal] Stats widgets: migrate the site picker from SiriKit to App Intents [#25753]
77
* [*] Fix Blogging Reminders text color in dark mode [#25780]
88
* [*] Share extensions: Fix the site picker showing an error while sites are still loading [#25798]
9+
* [*] Share Extension: Fix a crash after uploading a post to WordPress.com [#25773]
910

1011
27.0
1112
-----

Tests/WordPressKitTests/WordPressKitTests/Tests/PostServiceRemoteRESTTests.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@ - (PostServiceRemoteREST*)service
2626
return [[PostServiceRemoteREST alloc] initWithWordPressComRestApi:api siteID:siteID];
2727
}
2828

29+
#pragma mark - Mapping posts
30+
31+
- (void)testThatRemotePostMappingConvertsStringSiteIDToNumber
32+
{
33+
NSDictionary *jsonPost = @{
34+
@"ID": @1147,
35+
@"site_ID": @"237072388"
36+
};
37+
38+
RemotePost *post = [PostServiceRemoteREST remotePostFromJSONDictionary:jsonPost];
39+
40+
XCTAssertEqualObjects(post.postID, @1147);
41+
XCTAssertEqualObjects(post.siteID, @237072388);
42+
XCTAssertTrue([post.siteID isKindOfClass:[NSNumber class]]);
43+
}
44+
45+
- (void)testThatRemotePostMappingPreservesNumericSiteID
46+
{
47+
NSDictionary *jsonPost = @{
48+
@"ID": @1147,
49+
@"site_ID": @237072388
50+
};
51+
52+
RemotePost *post = [PostServiceRemoteREST remotePostFromJSONDictionary:jsonPost];
53+
54+
XCTAssertEqualObjects(post.postID, @1147);
55+
XCTAssertEqualObjects(post.siteID, @237072388);
56+
XCTAssertTrue([post.siteID isKindOfClass:[NSNumber class]]);
57+
}
58+
2959
#pragma mark - Getting posts by ID
3060

3161
- (void)testThatGetPostWithIDWorks

0 commit comments

Comments
 (0)