Skip to content

Commit 6539b26

Browse files
nicklockwoodfacebook-github-bot-6
authored and
facebook-github-bot-6
committed
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: #3804) Reviewed By: javache Differential Revision: D2605713 fb-gh-sync-id: b4402c9ede5eb31dd38021c902f046a4e0557814
1 parent cb3a073 commit 6539b26

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m

+20
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ - (void)doFooWithDouble:(__unused double)n { }
6464
- (void)doFooWithInteger:(__unused NSInteger)n { }
6565
- (void)doFooWithCGRect:(CGRect)s { _s = s; }
6666

67+
- (void)doFoo : (__unused NSString *)foo { }
68+
6769
- (void)testNumbersNonnull
6870
{
6971
{
@@ -121,4 +123,22 @@ - (void)testStructArgument
121123
XCTAssertTrue(CGRectEqualToRect(r, _s));
122124
}
123125

126+
- (void)testWhitespaceTolerance
127+
{
128+
NSString *methodName = @"doFoo : \t (NSString *)foo";
129+
130+
__block RCTModuleMethod *method;
131+
XCTAssertFalse(RCTLogsError(^{
132+
method = [[RCTModuleMethod alloc] initWithObjCMethodName:methodName
133+
JSMethodName:nil
134+
moduleClass:[self class]];
135+
}));
136+
137+
XCTAssertEqualObjects(method.JSMethodName, @"doFoo");
138+
139+
XCTAssertFalse(RCTLogsError(^{
140+
[method invokeWithBridge:nil module:self arguments:@[@"bar"]];
141+
}));
142+
}
143+
124144
@end

React/Base/RCTModuleMethod.m

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ - (instancetype)initWithObjCMethodName:(NSString *)objCMethodName
130130
if (colonRange.location != NSNotFound) {
131131
methodName = [methodName substringToIndex:colonRange.location];
132132
}
133+
methodName = [methodName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
133134
RCTAssert(methodName.length, @"%@ is not a valid JS function name, please"
134135
" supply an alternative using RCT_REMAP_METHOD()", objCMethodName);
135136
methodName;

0 commit comments

Comments
 (0)