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

Issue-89 - Add support for arrays in query parameters #98

Closed
wants to merge 7 commits into from
11 changes: 10 additions & 1 deletion Tests/Categories/NSString_DPLQuerySpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,16 @@
it(@"should serialize multiple arrays from dictionary into the query string", ^{
NSDictionary *params = @{ @"beers": @[ @"stout", @"ale" ], @"liquors": @[ @"vodka", @"whiskey" ] };
NSString *query = [NSString DPL_queryStringWithParameters:params];
expect(query).to.equal(@"beers[]=stout&beers[]=ale&liquors[]=vodka&liquors[]=whiskey");

NSString *queryStringToMatch;
NSString *queryStringPartBeers = @"beers[]=stout&beers[]=ale";
NSString *queryStringPartLiquors = @"liquors[]=vodka&liquors[]=whiskey";
if ([[params allKeys][0] isEqualToString:@"beers"]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably have a suitable default here such as ordered ascending that way we can expect a consistent result.

Similarly, when parsing a url, I would expect to have the parameter order preserved so re-serialization mirrors the original url though that can't really happen in the category (#15) without more information.

For example:

NSURL *url = [NSURL URLWithString:@"dpl://something/?liquors[]=vodka&liquors[]=whiskey&beers[]=stout&beers[]=ale"];
DPLDeepLink *link = [[DPLDeepLink alloc] initWithURL:url];
link.URL.query  // should serialize as => @"liquors[]=vodka&liquors[]=whiskey&beers[]=stout&beers[]=ale"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wessmith Just making sure I understand that correctly: you are talking here about DPLMutableDeepLink not DPLDeepLinkright? (DPLDeepLink returns previously set URL without any serialization work).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Yeah.

queryStringToMatch = [NSString stringWithFormat:@"%@&%@", queryStringPartBeers, queryStringPartLiquors];
} else {
queryStringToMatch = [NSString stringWithFormat:@"%@&%@", queryStringPartLiquors, queryStringPartBeers];
}
expect(query).to.equal(queryStringToMatch);
});

it(@"should percent encode parameters from dictionary into the query array", ^{
Expand Down