Skip to content

Commit faaef5b

Browse files
author
Wes Smith
committed
preserve non-pair query items
1 parent 7735a9c commit faaef5b

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

DeepLinkKit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -993,34 +993,34 @@
993993
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-frameworks.sh\"\n";
994994
showEnvVarsInLog = 0;
995995
};
996-
F7AECAC5E12B21557769080B /* Embed Pods Frameworks */ = {
996+
DE56F9AB1BD6B0140090BF8C /* Specta Focus Check */ = {
997997
isa = PBXShellScriptBuildPhase;
998998
buildActionMask = 2147483647;
999999
files = (
10001000
);
10011001
inputPaths = (
10021002
);
1003-
name = "Embed Pods Frameworks";
1003+
name = "Specta Focus Check";
10041004
outputPaths = (
10051005
);
10061006
runOnlyForDeploymentPostprocessing = 0;
10071007
shellPath = /bin/sh;
1008-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReceiverDemoSwift/Pods-ReceiverDemoSwift-frameworks.sh\"\n";
1009-
showEnvVarsInLog = 0;
1008+
shellScript = "\"${SRCROOT}/Tests/BuildScripts/specta-focus-check.sh\"";
10101009
};
1011-
DE56F9AB1BD6B0140090BF8C /* Specta Focus Check */ = {
1010+
F7AECAC5E12B21557769080B /* Embed Pods Frameworks */ = {
10121011
isa = PBXShellScriptBuildPhase;
10131012
buildActionMask = 2147483647;
10141013
files = (
10151014
);
10161015
inputPaths = (
10171016
);
1018-
name = "Specta Focus Check";
1017+
name = "Embed Pods Frameworks";
10191018
outputPaths = (
10201019
);
10211020
runOnlyForDeploymentPostprocessing = 0;
10221021
shellPath = /bin/sh;
1023-
shellScript = "\"${SRCROOT}/Tests/BuildScripts/specta-focus-check.sh\"";
1022+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ReceiverDemoSwift/Pods-ReceiverDemoSwift-frameworks.sh\"\n";
1023+
showEnvVarsInLog = 0;
10241024
};
10251025
/* End PBXShellScriptBuildPhase section */
10261026

@@ -1169,6 +1169,7 @@
11691169
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
11701170
ONLY_ACTIVE_ARCH = YES;
11711171
SDKROOT = iphoneos;
1172+
STRIP_INSTALLED_PRODUCT = NO;
11721173
TARGETED_DEVICE_FAMILY = "1,2";
11731174
};
11741175
name = Debug;
@@ -1403,6 +1404,7 @@
14031404
IPHONEOS_DEPLOYMENT_TARGET = 7.1;
14041405
ONLY_ACTIVE_ARCH = YES;
14051406
SDKROOT = iphoneos;
1407+
STRIP_INSTALLED_PRODUCT = NO;
14061408
TARGETED_DEVICE_FAMILY = "1,2";
14071409
};
14081410
name = Test;

DeepLinkKit/Categories/NSString+DPLQuery.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ + (NSString *)DPL_queryStringWithParameters:(NSDictionary *)parameters {
88
NSString *value = [parameters[key] description];
99
key = [key DPL_stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
1010
value = [value DPL_stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
11-
[query appendFormat:@"%@%@=%@", (idx > 0) ? @"&" : @"", key, value];
11+
[query appendFormat:@"%@%@%@%@", (idx > 0) ? @"&" : @"", key, (value.length > 0) ? @"=" : @"", value];
1212
}];
1313
return [query copy];
1414
}
@@ -19,11 +19,17 @@ - (NSDictionary *)DPL_parametersFromQueryString {
1919
NSMutableDictionary *paramsDict = [NSMutableDictionary dictionaryWithCapacity:[params count]];
2020
for (NSString *param in params) {
2121
NSArray *pairs = [param componentsSeparatedByString:@"="];
22-
if ([pairs count] == 2) {
22+
if (pairs.count == 2) {
23+
// e.g. ?key=value
2324
NSString *key = [pairs[0] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2425
NSString *value = [pairs[1] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2526
paramsDict[key] = value;
2627
}
28+
else if (pairs.count == 1) {
29+
// e.g. ?key
30+
NSString *key = [[pairs firstObject] DPL_stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
31+
paramsDict[key] = @"";
32+
}
2733
}
2834
return [paramsDict copy];
2935
}

Tests/Categories/NSString_DPLQuerySpec.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
expect(query).to.equal(@"one=1&two=2");
4545
});
4646

47+
it(@"serializes keys with empty value", ^{
48+
NSDictionary *params = @{ @"one": @"", @"two": @2 };
49+
NSString *query = [NSString DPL_queryStringWithParameters:params];
50+
expect(query).to.equal(@"one&two=2");
51+
});
52+
4753
it(@"should percent encode parameters from dictionary into the query string", ^{
4854
NSDictionary *params = @{ @"one": @"a one", @"two": @"http://www.example.com?foo=bar" };
4955
NSString *query = [NSString DPL_queryStringWithParameters:params];
@@ -61,11 +67,11 @@
6167
expect(params[@"two"]).to.equal(@"2");
6268
});
6369

64-
it(@"should ignore incomplete pairs in a query string", ^{
70+
it(@"does NOT discard incomplete pairs in a query string", ^{
6571
NSString *query = @"one=1&two&three=3";
6672
NSDictionary *params = [query DPL_parametersFromQueryString];
6773
expect(params[@"one"]).to.equal(@"1");
68-
expect(params[@"two"]).to.beNil();
74+
expect(params[@"two"]).to.equal(@"");
6975
expect(params[@"three"]).to.equal(@"3");
7076
});
7177

Tests/DeepLink/DPLDeepLinkSpec.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
};
4343
expect(link[@"partner"]).to.equal(@"not-uber");
4444
});
45+
46+
it(@"preserves key only query items", ^{
47+
NSURL *url = [NSURL URLWithString:@"seamlessapp://menu?293147"];
48+
DPLDeepLink *link = [[DPLDeepLink alloc] initWithURL:url];
49+
expect(link.queryParameters[@"293147"]).to.equal(@"");
50+
expect(link.URL.absoluteString).to.equal(@"seamlessapp://menu?293147");
51+
});
4552
});
4653

4754

Tests/DeepLink/DPLMutableDeepLinkSpec.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
link.path = @"/path/to/there";
8888
expect(link.URL.absoluteString).to.equal(@"dpl://dpl.com/path/to/there?");
8989
});
90+
91+
it(@"preserves key only query items", ^{
92+
DPLMutableDeepLink *link = [[DPLMutableDeepLink alloc] initWithString:@"seamlessapp://menu?293147"];
93+
expect(link.queryParameters[@"293147"]).to.equal(@"");
94+
expect(link.URL.absoluteString).to.equal(@"seamlessapp://menu?293147");
95+
});
9096
});
9197

9298

0 commit comments

Comments
 (0)