From ef4f849b9554fdc1b9ad02f790d45e4f5e5ca96e Mon Sep 17 00:00:00 2001 From: Wes Smith Date: Tue, 20 Oct 2015 16:43:19 -0400 Subject: [PATCH] preserve non-pair query items --- DeepLinkKit.xcodeproj/project.pbxproj | 16 +++++++++------- DeepLinkKit/Categories/NSString+DPLQuery.m | 10 ++++++++-- Tests/Categories/NSString_DPLQuerySpec.m | 10 ++++++++-- Tests/DeepLink/DPLDeepLinkSpec.m | 7 +++++++ Tests/DeepLink/DPLMutableDeepLinkSpec.m | 6 ++++++ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/DeepLinkKit.xcodeproj/project.pbxproj b/DeepLinkKit.xcodeproj/project.pbxproj index ead3900..a0090ce 100644 --- a/DeepLinkKit.xcodeproj/project.pbxproj +++ b/DeepLinkKit.xcodeproj/project.pbxproj @@ -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 */ @@ -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; @@ -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; diff --git a/DeepLinkKit/Categories/NSString+DPLQuery.m b/DeepLinkKit/Categories/NSString+DPLQuery.m index c0b20b2..df99304 100644 --- a/DeepLinkKit/Categories/NSString+DPLQuery.m +++ b/DeepLinkKit/Categories/NSString+DPLQuery.m @@ -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]; } @@ -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]; } diff --git a/Tests/Categories/NSString_DPLQuerySpec.m b/Tests/Categories/NSString_DPLQuerySpec.m index 653e39e..191ac26 100644 --- a/Tests/Categories/NSString_DPLQuerySpec.m +++ b/Tests/Categories/NSString_DPLQuerySpec.m @@ -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]; @@ -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"); }); diff --git a/Tests/DeepLink/DPLDeepLinkSpec.m b/Tests/DeepLink/DPLDeepLinkSpec.m index a97be3f..6ad33fd 100644 --- a/Tests/DeepLink/DPLDeepLinkSpec.m +++ b/Tests/DeepLink/DPLDeepLinkSpec.m @@ -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"); + }); }); diff --git a/Tests/DeepLink/DPLMutableDeepLinkSpec.m b/Tests/DeepLink/DPLMutableDeepLinkSpec.m index b706614..38ab14f 100644 --- a/Tests/DeepLink/DPLMutableDeepLinkSpec.m +++ b/Tests/DeepLink/DPLMutableDeepLinkSpec.m @@ -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"); + }); });