Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode the style URL in iOS #2965

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions platform/darwin/src/http_file_source.mm
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ BOOL isValidMapboxEndpoint(NSURL *url) {
MLN_APPLE_EXPORT
NSURL *resourceURL(const Resource& resource) {

NSURL *url = [NSURL URLWithString:@(resource.url.c_str())];

NSString *encodedUrlString = [@(resource.url.c_str()) stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
NSURL *url = [NSURL URLWithString:encodedUrlString];

#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
if (isValidMapboxEndpoint(url)) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
Expand Down
11 changes: 11 additions & 0 deletions platform/darwin/test/MLNResourceTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ - (void)testOfflineQueryParameterIsAddedForOfflineResourceForChina {
[self internalTestOfflineQueryParameterIsAddedForOfflineResource:testURL];
}

- (void)testResourceURL {
using namespace mbgl;

// Test URL with characters requiring encoding
Resource resource(Resource::Kind::Unknown, "https://example.com/test?param1=a|b&param2=c|d");
NSURL *url = resourceURL(resource);

XCTAssertNotNil(url);
XCTAssertEqualObjects(url.absoluteString, @"https://example.com/test?param1=a%7Cb&param2=c%7Cd");
}

@end
Loading