Fixed whitespace bug with RCTModuleMethod parsing
Summary: public White space between the end of the first part of the method selector and the first colon was being included in the JS method name. (See: https://github.com/facebook/react-native/issues/3804) Reviewed By: javache Differential Revision: D2605713 fb-gh-sync-id: b4402c9ede5eb31dd38021c902f046a4e0557814
This commit is contained in:
parent
cb3a07306e
commit
6539b26810
|
@ -64,6 +64,8 @@ static BOOL RCTLogsError(void (^block)(void))
|
|||
- (void)doFooWithInteger:(__unused NSInteger)n { }
|
||||
- (void)doFooWithCGRect:(CGRect)s { _s = s; }
|
||||
|
||||
- (void)doFoo : (__unused NSString *)foo { }
|
||||
|
||||
- (void)testNumbersNonnull
|
||||
{
|
||||
{
|
||||
|
@ -121,4 +123,22 @@ static BOOL RCTLogsError(void (^block)(void))
|
|||
XCTAssertTrue(CGRectEqualToRect(r, _s));
|
||||
}
|
||||
|
||||
- (void)testWhitespaceTolerance
|
||||
{
|
||||
NSString *methodName = @"doFoo : \t (NSString *)foo";
|
||||
|
||||
__block RCTModuleMethod *method;
|
||||
XCTAssertFalse(RCTLogsError(^{
|
||||
method = [[RCTModuleMethod alloc] initWithObjCMethodName:methodName
|
||||
JSMethodName:nil
|
||||
moduleClass:[self class]];
|
||||
}));
|
||||
|
||||
XCTAssertEqualObjects(method.JSMethodName, @"doFoo");
|
||||
|
||||
XCTAssertFalse(RCTLogsError(^{
|
||||
[method invokeWithBridge:nil module:self arguments:@[@"bar"]];
|
||||
}));
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -130,6 +130,7 @@ void RCTParseObjCMethodName(NSString **objCMethodName, NSArray **arguments)
|
|||
if (colonRange.location != NSNotFound) {
|
||||
methodName = [methodName substringToIndex:colonRange.location];
|
||||
}
|
||||
methodName = [methodName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
RCTAssert(methodName.length, @"%@ is not a valid JS function name, please"
|
||||
" supply an alternative using RCT_REMAP_METHOD()", objCMethodName);
|
||||
methodName;
|
||||
|
|
Loading…
Reference in New Issue