Fixed iOS 7 support for URL query functions

Summary:
public
Unfortunately, it turns out that NSURLComponents.queryItems only works on iOS 8 and above. This diff re-implements the RCTGetURLQueryParam and RCTURLByReplacingQueryParam functions using functionality available in iOS 7.

Reviewed By: javache

Differential Revision: D2803679

fb-gh-sync-id: 56f10bef4894d16197975b6023b7aa5ab106d8cb
This commit is contained in:
Nick Lockwood
2016-01-05 12:50:25 -08:00
committed by facebook-github-bot-4
parent 2462c8f87d
commit 180fc06b7a
2 changed files with 46 additions and 8 deletions

View File

@@ -30,6 +30,13 @@
XCTAssertEqualObjects(bar, @"foo");
}
- (void)testGetEncodedParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=You%20%26%20Me"];
NSString *foo = RCTGetURLQueryParam(URL, @"foo");
XCTAssertEqualObjects(foo, @"You & Me");
}
- (void)testQueryParamNotFound
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=bar"];
@@ -58,6 +65,13 @@
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?foo=foo&bar=foo");
}
- (void)testReplaceEncodedParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?foo=You%20%26%20Me"];
NSURL *result = RCTURLByReplacingQueryParam(URL, @"foo", @"Me & You");
XCTAssertEqualObjects(result.absoluteString, @"http://example.com?foo=Me%20%26%20You");
}
- (void)testAppendParam
{
NSURL *URL = [NSURL URLWithString:@"http://example.com?bar=foo"];