RKPathMatcher can now accommodate non-KVM dots that follow parameter keys in the pattern. Where /:filename.json would fail before, we use special escapes like /:filename\.json ... this fixes #349. Thanks @jverkoey for the fix and @coryalder for the catch.

This commit is contained in:
Greg Combs
2011-09-16 15:35:27 -05:00
parent 68afe008f7
commit c49310162e
15 changed files with 457 additions and 63 deletions

View File

@@ -37,11 +37,19 @@
* Register a mapping from an object class to a resource path. This resourcePath can be static
* (i.e. /this/is/the/path) or dynamic (i.e. /users/:userID/:username). Dynamic routes are
* evaluated against the object being routed using Key-Value coding and coerced into a string.
* *NOTE* - The pattern matcher fully supports KVM, so /:key1.otherKey normally resolves as it
* would in any other KVM situation, ... otherKey is a sub-key on a the object represented by
* key1. This presents a problem in situations where you might want to build a pattern like
* /:filename.json, where the dot isn't intended as a sub-key on the dynamic "filename", but
* rather it is part of the "json" static string. In these instances, you need to escape the
* dot with two backslashes, like so: /:filename\\.json
* @see RKPathMatcher
*/
- (void)routeClass:(Class)objectClass toResourcePath:(NSString*)resourcePath;
/**
* Register a mapping from an object class to a resource path for a specific HTTP method.
* @see RKPathMatcher
*/
- (void)routeClass:(Class)objectClass toResourcePath:(NSString*)resourcePath forMethod:(RKRequestMethod)method;
@@ -52,9 +60,13 @@
* For example, if your Person model has a string attribute titled "polymorphicResourcePath" that returns
* @"/this/is/the/path", you should configure the route with url escapes 'off', otherwise the router will return
* @"%2Fthis%2Fis%2Fthe%2Fpath".
* @see RKPathMatcher
*/
- (void)routeClass:(Class)objectClass toResourcePath:(NSString*)resourcePath forMethod:(RKRequestMethod)method escapeRoutedPath:(BOOL)addEscapes;
/**
* Returns the resource path to send requests for a given object and HTTP method
*/
- (NSString*)resourcePathForObject:(NSObject*)object method:(RKRequestMethod)method;
@end

View File

@@ -57,10 +57,16 @@
Pattern strings should include encoded parameter keys, delimited by a single colon at the
beginning of the key name.
*NOTE* - Numerous colon-encoded parameter keys can be joined in a long pattern, but each key must be
separated by at least one unmapped character. For instance, /:key1:key2:key3/ is invalid, wheras
*NOTE 1* - Numerous colon-encoded parameter keys can be joined in a long pattern, but each key must be
separated by at least one unmapped character. For instance, /:key1:key2:key3/ is invalid, whereas
/:key1/:key2/:key3/ is acceptable.
*NOTE 2* - The pattern matcher supports KVM, so :key1.otherKey normally resolves as it would in any other KVM
situation, ... otherKey is a sub-key on a the object represented by key1. This presents problems in circumstances where
you might want to build a pattern like /:filename.json, where the dot isn't intended as a sub-key on the filename, but rather
part of the json static string. In these instances, you need to escape the dot with two backslashes, like so:
/:filename\\.json
@param patternString The pattern to use for evaluating, such as /:entityName/:stateID/:chamber/
@param shouldTokenize If YES, any query parameters will be tokenized and inserted into the parsed argument dictionary.
@param arguments A pointer to a dictionary that contains the key/values from the pattern (and parameter) matching.
@@ -73,10 +79,16 @@
matchesPath:tokenizeQueryStrings:parsedArguments: Patterns should include encoded parameter keys,
delimited by a single colon at the beginning of the key name.
*NOTE* - Numerous colon-encoded parameter keys can be joined in a long pattern, but each key must be
separated by at least one unmapped character. For instance, /:key1:key2:key3/ is invalid, wheras
*NOTE 1* - Numerous colon-encoded parameter keys can be joined in a long pattern, but each key must be
separated by at least one unmapped character. For instance, /:key1:key2:key3/ is invalid, whereas
/:key1/:key2/:key3/ is acceptable.
*NOTE 2* - The pattern matcher supports KVM, so :key1.otherKey normally resolves as it would in any other KVM
situation, ... otherKey is a sub-key on a the object represented by key1. This presents problems in circumstances where
you might want to build a pattern like /:filename.json, where the dot isn't intended as a sub-key on the filename, but rather
part of the json static string. In these instances, you need to escape the dot with two backslashes, like so:
/:filename\\.json
@param patternString The pattern to use for evaluating, such as /:entityName/:stateID/:chamber/
@return An instantiated RKPathMatcher with an established pattern.
*/

View File

@@ -115,7 +115,7 @@ NSString *RKEncodeURLString(NSString *unencodedString) {
RKLogWarning(@"The parsed arguments dictionary reference is nil.");
return YES;
}
NSDictionary *extracted = [self.socPattern extractParameterKeyValuesFromSourceString:self.rootPath];
NSDictionary *extracted = [self.socPattern parameterDictionaryFromSourceString:self.rootPath];
if (extracted)
[argumentsCollection addEntriesFromDictionary:[extracted removePercentEscapesFromKeysAndObjects]];
*arguments = argumentsCollection;