Skip to content

Preserve query items without a value #73

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

Merged
merged 1 commit into from
Dec 22, 2015
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
16 changes: 9 additions & 7 deletions DeepLinkKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -993,34 +993,34 @@
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F7AECAC5E12B21557769080B /* Embed Pods Frameworks */ = {
DE56F9AB1BD6B0140090BF8C /* Specta Focus Check */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
name = "Specta Focus Check";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReceiverDemoSwift/Pods-ReceiverDemoSwift-frameworks.sh\"\n";
showEnvVarsInLog = 0;
shellScript = "\"${SRCROOT}/Tests/BuildScripts/specta-focus-check.sh\"";
};
DE56F9AB1BD6B0140090BF8C /* Specta Focus Check */ = {
F7AECAC5E12B21557769080B /* Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Specta Focus Check";
name = "Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Tests/BuildScripts/specta-focus-check.sh\"";
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReceiverDemoSwift/Pods-ReceiverDemoSwift-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -1169,6 +1169,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
STRIP_INSTALLED_PRODUCT = NO;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -1403,6 +1404,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
STRIP_INSTALLED_PRODUCT = NO;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Test;
Expand Down
10 changes: 8 additions & 2 deletions DeepLinkKit/Categories/NSString+DPLQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ + (NSString *)DPL_queryStringWithParameters:(NSDictionary *)parameters {
NSString *value = [parameters[key] description];
key = [key DPL_stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
value = [value DPL_stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[query appendFormat:@"%@%@=%@", (idx > 0) ? @"&" : @"", key, value];
[query appendFormat:@"%@%@%@%@", (idx > 0) ? @"&" : @"", key, (value.length > 0) ? @"=" : @"", value];
}];
return [query copy];
}
Expand All @@ -19,11 +19,17 @@ - (NSDictionary *)DPL_parametersFromQueryString {
NSMutableDictionary *paramsDict = [NSMutableDictionary dictionaryWithCapacity:[params count]];
for (NSString *param in params) {
NSArray *pairs = [param componentsSeparatedByString:@"="];
if ([pairs count] == 2) {
if (pairs.count == 2) {
// e.g. ?key=value
NSString *key = [pairs[0] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *value = [pairs[1] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
paramsDict[key] = value;
}
else if (pairs.count == 1) {
// e.g. ?key
NSString *key = [[pairs firstObject] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
paramsDict[key] = @"";
}
}
return [paramsDict copy];
}
Expand Down
10 changes: 8 additions & 2 deletions Tests/Categories/NSString_DPLQuerySpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
expect(query).to.equal(@"one=1&two=2");
});

it(@"serializes keys with empty value", ^{
NSDictionary *params = @{ @"one": @"", @"two": @2 };
NSString *query = [NSString DPL_queryStringWithParameters:params];
expect(query).to.equal(@"one&two=2");
});

it(@"should percent encode parameters from dictionary into the query string", ^{
NSDictionary *params = @{ @"one": @"a one", @"two": @"http://www.example.com?foo=bar" };
NSString *query = [NSString DPL_queryStringWithParameters:params];
Expand All @@ -61,11 +67,11 @@
expect(params[@"two"]).to.equal(@"2");
});

it(@"should ignore incomplete pairs in a query string", ^{
it(@"does NOT discard incomplete pairs in a query string", ^{
NSString *query = @"one=1&two&three=3";
NSDictionary *params = [query DPL_parametersFromQueryString];
expect(params[@"one"]).to.equal(@"1");
expect(params[@"two"]).to.beNil();
expect(params[@"two"]).to.equal(@"");
expect(params[@"three"]).to.equal(@"3");
});

Expand Down
7 changes: 7 additions & 0 deletions Tests/DeepLink/DPLDeepLinkSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
};
expect(link[@"partner"]).to.equal(@"not-uber");
});

it(@"preserves key only query items", ^{
NSURL *url = [NSURL URLWithString:@"seamlessapp://menu?293147"];
DPLDeepLink *link = [[DPLDeepLink alloc] initWithURL:url];
expect(link.queryParameters[@"293147"]).to.equal(@"");
expect(link.URL.absoluteString).to.equal(@"seamlessapp://menu?293147");
});
});


Expand Down
6 changes: 6 additions & 0 deletions Tests/DeepLink/DPLMutableDeepLinkSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
link.path = @"/path/to/there";
expect(link.URL.absoluteString).to.equal(@"dpl://dpl.com/path/to/there?");
});

it(@"preserves key only query items", ^{
DPLMutableDeepLink *link = [[DPLMutableDeepLink alloc] initWithString:@"seamlessapp://menu?293147"];
expect(link.queryParameters[@"293147"]).to.equal(@"");
expect(link.URL.absoluteString).to.equal(@"seamlessapp://menu?293147");
});
});


Expand Down