Skip to content

Commit e713354

Browse files
author
RadAzzouz
committed
Add missing document validation checks
1 parent dc2294e commit e713354

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ios/RCTPSPDFKit/RCTPSPDFKitView.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ - (void)flexibleToolbarContainerDidHide:(PSPDFFlexibleToolbarContainer *)contain
173173
#pragma mark - Instant JSON
174174

175175
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAnnotations:(PSPDFPageIndex)pageIndex type:(PSPDFAnnotationType)type {
176-
NSArray <PSPDFAnnotation *> *annotations = [self.pdfController.document annotationsForPageAtIndex:pageIndex type:type];
176+
PSPDFDocument *document = self.pdfController.document;
177+
if (!document.isValid) {
178+
NSLog(@"Document is invalid.");
179+
return nil;
180+
}
181+
182+
NSArray <PSPDFAnnotation *> *annotations = [document annotationsForPageAtIndex:pageIndex type:type];
177183
NSArray <NSDictionary *> *annotationsJSON = [RCTConvert instantJSONFromAnnotations:annotations];
178184
return @{@"annotations" : annotationsJSON};
179185
}
@@ -234,8 +240,14 @@ - (BOOL)removeAnnotationWithUUID:(NSString *)annotationUUID {
234240
}
235241

236242
- (NSDictionary<NSString *, NSArray<NSDictionary *> *> *)getAllUnsavedAnnotations {
237-
PSPDFDocumentProvider *documentProvider = self.pdfController.document.documentProviders.firstObject;
238-
NSData *data = [self.pdfController.document generateInstantJSONFromDocumentProvider:documentProvider error:NULL];
243+
PSPDFDocument *document = self.pdfController.document;
244+
if (!document.isValid) {
245+
NSLog(@"Document is invalid.");
246+
return nil;
247+
}
248+
249+
PSPDFDocumentProvider *documentProvider = document.documentProviders.firstObject;
250+
NSData *data = [document generateInstantJSONFromDocumentProvider:documentProvider error:NULL];
239251
NSDictionary *annotationsJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:NULL];
240252
return annotationsJSON;
241253
}

0 commit comments

Comments
 (0)