Skip to content

Commit 78e9ad0

Browse files
committed
Fixed construction of urls with path that ends with forward slash.
1 parent e377d72 commit 78e9ad0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Parse/Internal/HTTPRequest/PFURLConstructor.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ + (NSURL *)URLFromAbsoluteString:(NSString *)string
2424
if (path.length != 0) {
2525
NSString *fullPath = (components.path.length ? components.path : @"/");
2626
fullPath = [fullPath stringByAppendingPathComponent:path];
27+
// If the last character in the provided path is a `/` -> `stringByAppendingPathComponent:` will remove it.
28+
// so we need to append it manually to make sure we contruct with the requested behavior.
29+
if ([path characterAtIndex:path.length - 1] == '/' &&
30+
[fullPath characterAtIndex:fullPath.length - 1] != '/') {
31+
fullPath = [fullPath stringByAppendingString:@"/"];
32+
}
2733
components.path = fullPath;
2834
}
2935
if (query) {

Tests/Unit/URLConstructorTests.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ - (void)testURLWithPath {
6161
path:@"/100500/yolo"
6262
query:nil].absoluteString,
6363
@"https://yolo.com/abc/xyz/100500/yolo");
64+
XCTAssertEqualObjects([PFURLConstructor URLFromAbsoluteString:@"https://yolo.com/"
65+
path:@"/yolo/"
66+
query:nil].absoluteString,
67+
@"https://yolo.com/yolo/");
68+
XCTAssertEqualObjects([PFURLConstructor URLFromAbsoluteString:@"https://yolo.com/"
69+
path:@"a/yolo/"
70+
query:nil].absoluteString,
71+
@"https://yolo.com/a/yolo/");
72+
XCTAssertEqualObjects([PFURLConstructor URLFromAbsoluteString:@"https://yolo.com/"
73+
path:@"/a/yolo/"
74+
query:nil].absoluteString,
75+
@"https://yolo.com/a/yolo/");
6476
}
6577

6678
@end

0 commit comments

Comments
 (0)