Skip to content

Commit

Permalink
Merge pull request #73 from usebutton/wes/preserve_non-pair_query_items
Browse files Browse the repository at this point in the history
Preserve query items without a value
  • Loading branch information
wessmith committed Dec 22, 2015
2 parents a6c7644 + ef4f849 commit 36d6799
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
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

0 comments on commit 36d6799

Please sign in to comment.