From 6539b268108f1a6976cdda7b393f4abbbe82188e Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Mon, 2 Nov 2015 08:51:17 -0800 Subject: [PATCH] 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 --- .../RCTModuleMethodTests.m | 20 +++++++++++++++++++ React/Base/RCTModuleMethod.m | 1 + 2 files changed, 21 insertions(+) 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;