Skip to content

Commit c4d66ac

Browse files
Mykola MokhnachFacebook Github Bot
authored andcommitted
Avoid crash for some special XPath queries by explicitly checking whether result nodeSet is empty or not
Summary: Based on facebookarchive#403 Closes facebookarchive#404 Differential Revision: D4298605 Pulled By: marekcirkos fbshipit-source-id: 44e9d91a26ceac42dc7f20e3ac0188f8013c0771
1 parent 78449f9 commit c4d66ac

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

WebDriverAgentLib/Utilities/FBXPath.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ + (nullable NSString *)xmlStringWithSnapshot:(XCElementSnapshot *)root
8989

9090
+ (NSArray *)collectMatchingSnapshots:(xmlNodeSetPtr)nodeSet elementStore:(NSMutableDictionary *)elementStore
9191
{
92+
if (xmlXPathNodeSetIsEmpty(nodeSet)) {
93+
return @[];
94+
}
9295
NSMutableArray *matchingSnapshots = [NSMutableArray array];
9396
const xmlChar *indexPathKeyName = [FBXPath xmlCharPtrForInput:[kXMLIndexPathKey cStringUsingEncoding:NSUTF8StringEncoding]];
9497
for (NSInteger i = 0; i < nodeSet->nodeNr; i++) {

WebDriverAgentTests/IntegrationTests/XCUIElementFBFindTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,10 @@ - (void)testDescendantsWithPropertyPartial
186186
XCTAssertEqualObjects(matchingSnapshots.lastObject.label, @"Alerts");
187187
}
188188

189+
- (void)testSpecialXPathQuery
190+
{
191+
NSArray<XCUIElement *> *matchingSnapshots = [self.testedView fb_descendantsMatchingXPathQuery:@".//XCUIElementTypeButton[@label=\"Alerts\"]" shouldReturnAfterFirstMatch:NO];
192+
XCTAssertEqual(matchingSnapshots.count, 0);
193+
}
194+
189195
@end

0 commit comments

Comments
 (0)