Rework path based response descriptor matching and expand test coverage. Eliminate path normalization. fixes #987

This commit is contained in:
Blake Watters
2012-10-14 13:46:38 -04:00
parent 4a7ed3cbd3
commit f3ece00743
13 changed files with 300 additions and 109 deletions

View File

@@ -22,7 +22,6 @@
#import "SOCKit.h"
#import "RKLog.h"
#import "RKDictionaryUtilities.h"
#import "RKPathUtilities.h"
static NSString *RKEncodeURLString(NSString *unencodedString);
extern NSDictionary *RKQueryParametersFromStringWithEncoding(NSString *string, NSStringEncoding stringEncoding);
@@ -77,12 +76,6 @@ static NSString *RKEncodeURLString(NSString *unencodedString)
return matcher;
}
// Normalize our root path for matching cleanly with SOCKit
- (void)setRootPath:(NSString *)rootPath
{
_rootPath = RKPathNormalize(rootPath);
}
- (BOOL)matches
{
NSAssert((self.socPattern != NULL && self.rootPath != NULL), @"Matcher is insufficiently configured. Before attempting pattern matching, you must provide a path string and a pattern to match it against.");
@@ -145,10 +138,11 @@ static NSString *RKEncodeURLString(NSString *unencodedString)
NSAssert(self.socPattern != NULL, @"Matcher has no established pattern. Instantiate it using pathMatcherWithPattern: before calling pathFromObject:");
NSAssert(object != NULL, @"Object provided is invalid; cannot create a path from a NULL object");
NSString *(^encoderBlock)(NSString *interpolatedString) = nil;
if (addEscapes)
if (addEscapes) {
encoderBlock = ^NSString *(NSString *interpolatedString) {
return RKEncodeURLString(interpolatedString);
};
}
NSString *path = [self.socPattern stringFromObject:object withBlock:encoderBlock];
return path;
}

View File

@@ -55,11 +55,3 @@ NSString *RKPathFromPatternWithObject(NSString *pathPattern, id object);
@return The expected MIME Type of the resource identified by the path or nil if unknown.
*/
NSString *RKMIMETypeFromPathExtension(NSString *path);
/**
Normalizes a given string into a path by ensuring that it includes a leading slash and does not include a trailing slash.
@param path The path to be normalized.
@return The given path, normalized with a leading slash and without a trailing sla
*/
NSString *RKPathNormalize(NSString *path);

View File

@@ -119,12 +119,3 @@ NSString *RKMIMETypeFromPathExtension(NSString *path)
// Consult our internal dictionary of mappings if not found
return [RKDictionaryOfFileExtensionsToMIMETypes() valueForKey:pathExtension];
}
NSString *RKPathNormalize(NSString *path)
{
path = [path stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
NSUInteger length = [path length];
if ([path characterAtIndex:length - 1] == '/') path = [path substringToIndex:length - 1];
if ([path characterAtIndex:0] != '/') path = [NSString stringWithFormat:@"/%@", path];
return path;
}