diff --git a/Code/Support/RKPathMatcher.m b/Code/Support/RKPathMatcher.m index 332293d7..562e41e7 100644 --- a/Code/Support/RKPathMatcher.m +++ b/Code/Support/RKPathMatcher.m @@ -140,7 +140,14 @@ static NSString *RKEncodeURLString(NSString *unencodedString) } NSString *path = [self.socPattern stringFromObject:object withBlock:encoderBlock]; if (interpolatedParameters) { - *interpolatedParameters = [self.socPattern parameterDictionaryFromSourceString:path]; + NSMutableDictionary *parsedParameters = [[self.socPattern parameterDictionaryFromSourceString:path] mutableCopy]; + if (addEscapes) { + for (NSString *key in [parsedParameters allKeys]) { + NSString *unescapedParameter = [[parsedParameters objectForKey:key] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + [parsedParameters setValue:unescapedParameter forKey:key]; + } + } + *interpolatedParameters = parsedParameters; } return path; } diff --git a/Tests/Logic/Support/RKPathMatcherTest.m b/Tests/Logic/Support/RKPathMatcherTest.m index 947a7ccd..e087e471 100755 --- a/Tests/Logic/Support/RKPathMatcherTest.m +++ b/Tests/Logic/Support/RKPathMatcherTest.m @@ -125,6 +125,16 @@ expect(interpolatedPath).to.equal(expectedPath); } +- (void)testThatEscapedParametersAreUnescapedWhenCreatingPathFromObject +{ + NSDictionary *arguments = @{ @"name": @"Blake Watters" }; + RKPathMatcher *matcher = [RKPathMatcher pathMatcherWithPattern:@"/names/:name"]; + NSDictionary *params = nil; + [matcher pathFromObject:arguments addingEscapes:YES interpolatedParameters:¶ms]; + expect(params).notTo.beNil(); + expect([params objectForKey:@"name"]).to.equal(@"Blake Watters"); +} + - (void)testMatchingPathWithTrailingSlashAndQuery { RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/api/v1/organizations/"];