Skip to content

Commit 521d559

Browse files
committed
Properly bail on encoding errors, add tests
1 parent aa269ca commit 521d559

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Parse/Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ + (instancetype)constructorWithDataSource:(id<PFInstallationIdentifierStoreProvi
7373
}
7474
NSError *error = nil;
7575
requestParameters = [[PFPointerObjectEncoder objectEncoder] encodeObject:parameters error:&error];
76+
PFBailTaskIfError(requestParameters, error);
7677
}
7778

7879
return [PFHTTPURLRequestConstructor urlRequestWithURL:url

Parse/Tests/Unit/CommandURLRequestConstructorTests.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,23 @@ - (void)testDefaultURLRequestHeaders {
157157
XCTAssertNotNil(headers[PFCommandHeaderNameAppDisplayVersion]);
158158
}
159159

160+
- (void)testBailOnEncodingError {
161+
id providerMock = [self mockedInstallationidentifierStoreProviderWithInstallationIdentifier:@"installationId"];
162+
NSURL *url = [NSURL URLWithString:@"https://parse.com/123"];
163+
PFCommandURLRequestConstructor *constructor = [PFCommandURLRequestConstructor constructorWithDataSource:providerMock serverURL:url];
164+
165+
PFRESTCommand *command = [PFRESTCommand commandWithHTTPPath:@"yolo"
166+
httpMethod:PFHTTPRequestMethodPOST
167+
parameters:@{ @"a" : [PFObject objectWithClassName:@"MyObject"] }
168+
sessionToken:@"yarr"
169+
error:nil];
170+
command.additionalRequestHeaders = @{ @"CustomHeader" : @"CustomValue" };
171+
NSError *error;
172+
NSURLRequest *request = [[constructor getDataURLRequestAsyncForCommand:command] waitForResult:&error];
173+
XCTAssertNil(request);
174+
XCTAssertNotNil(error);
175+
XCTAssertEqualObjects(error.domain, PFParseErrorDomain);
176+
XCTAssertEqualObjects(error.localizedDescription, @"Tried to save an object with a new, unsaved child.");
177+
}
178+
160179
@end

0 commit comments

Comments
 (0)