From 21af0ff4878f23033dd17d0e9bb5297070a5e39d Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Wed, 20 Nov 2019 12:44:39 -0500 Subject: [PATCH] [ios] Refactor host checks (#15948) --- platform/darwin/src/http_file_source.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index b0f69f4a7..dbf92aa46 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -195,14 +195,21 @@ HTTPFileSource::HTTPFileSource() HTTPFileSource::~HTTPFileSource() = default; +MGL_EXPORT +BOOL isValidMapboxEndpoint(NSURL *url) { + return ([url.host isEqualToString:@"mapbox.com"] || + [url.host hasSuffix:@".mapbox.com"] || + [url.host isEqualToString:@"mapbox.cn"] || + [url.host hasSuffix:@".mapbox.cn"]); +} + MGL_EXPORT NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountType) { NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - if (accountType == 0 && - ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) { + if (accountType == 0 && isValidMapboxEndpoint(url)) { NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; NSMutableArray *queryItems = [NSMutableArray array];