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

fix: query object been encoded again on iOS side #739

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 0 deletions .changeset/proud-ants-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/repack': patch
---

Fix url encoded twice issue on iOS side
13 changes: 10 additions & 3 deletions packages/repack/ios/ScriptConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ + (ScriptConfig *)fromConfig:(JS::NativeScriptManager::NormalizedScriptLocator &
withScriptId:(nonnull NSString *)scriptId
{
NSDictionary *_Nullable headers = (NSDictionary *)config.headers();
NSURLComponents *urlComponents = [NSURLComponents componentsWithString:config.url()];
urlComponents.query = config.query();
NSURL *url = urlComponents.URL;

NSString *urlString = config[@"url"];
NSString *query = config[@"query"];
NSString *finalURLString;
if (query != nil) {
finalURLString = [NSString stringWithFormat:@"%@?%@", urlString, query];
} else {
finalURLString = urlString;
}
NSURL *url = [NSURL URLWithString:finalURLString];
jbroma marked this conversation as resolved.
Show resolved Hide resolved

return [[ScriptConfig alloc] initWithScript:scriptId
withURL:url
Expand Down
10 changes: 10 additions & 0 deletions packages/repack/ios/ScriptManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,18 @@ - (void)downloadAndCache:(ScriptConfig *)config completionHandler:(void (^)(NSEr
NSURLSessionDataTask *task = [[NSURLSession sharedSession]
dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSInteger statusCode = [httpResponse statusCode];
if (error != nil) {
callback(error);
}else if(statusCode < 200 || statusCode >= 300){
NSDictionary *userInfo = @{
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Request should have returned with 200 HTTP status, but instead it received %ld", (long)statusCode]
};
NSError *httpError = [NSError errorWithDomain:NSURLErrorDomain
code:statusCode
userInfo:userInfo];
callback(httpError);
jbroma marked this conversation as resolved.
Show resolved Hide resolved
} else {
@try {
NSDictionary<NSString *, id> *result = [CodeSigningUtils extractBundleAndTokenWithFileContent:data];
Expand Down