Skip to content

Commit 42b36a8

Browse files
committed
Fix location dispatching
commit_hash:bc9284b4c05a93210487ea5579037d071f88b8c3
1 parent 26c7c86 commit 42b36a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

AppMetricaCore/Sources/Location/AMALocationDispatcher.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ - (void)cancelTimer
127127

128128
- (void)processRequest:(AMALocationRequest *)request
129129
{
130-
AMAArrayIterator *hostsProvider = [[AMAArrayIterator alloc] initWithArray:self.configuration.hosts];
130+
NSArray *hosts = self.configuration.hosts;
131+
if (hosts.count == 0) {
132+
AMALogError(@"Unable to retrieve host for location request");
133+
return;
134+
}
135+
136+
AMAArrayIterator *hostsProvider = [[AMAArrayIterator alloc] initWithArray:hosts];
131137

132138
if (request == nil) {
133139
NSError *internalError = [AMAErrorsFactory internalInconsistencyError:@"Failed to process location request"];

AppMetricaCore/Tests/AMALocationDispatcherTests.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
[[executor should] receive:@selector(executeAfterDelay:block:)];
154154
[dispatcher handleVisitAdd];
155155
});
156+
157+
it(@"Should not process request if no hosts are provided", ^{
158+
[configuration stub:@selector(hosts) andReturn:@[]];
159+
[[requestProcessor shouldNot] receive:@selector(processWithCallback:)];
160+
[dispatcher handleVisitAdd];
161+
});
156162

157163
context(@"Callback location", ^{
158164
beforeEach(^{

0 commit comments

Comments
 (0)