diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m index b11bffa26..a51319bb3 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m @@ -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 diff --git a/React/Base/RCTModuleMethod.m b/React/Base/RCTModuleMethod.m index 21d6447b4..f484142fc 100644 --- a/React/Base/RCTModuleMethod.m +++ b/React/Base/RCTModuleMethod.m @@ -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;