Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes wildcard resolving for non-existing paths (issue #814) #815

Merged
merged 1 commit into from Apr 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -73,7 +73,8 @@ NSComparisonResult prefixCompare(NSString *aString, NSString *bString);
/**
Resolves file paths that contain wildcards (*).
Returns the first path it can find, with all the wildcards resolved.
If it can't find a file with all wildcards resolved, it returns nil.
If it can't find a file with all wildcards resolved, it returns the
original path (possibly with wildcards).
Also standardizes path (resolves ~ for home path).
**/
- (NSString *)stringByResolvingWildcardsInPath;
Expand Down
14 changes: 11 additions & 3 deletions Quicksilver/Code-QuickStepFoundation/NSString_BLTRExtensions.m
Expand Up @@ -333,7 +333,7 @@ - (NSArray *)componentsSeparatedByStrings:(NSArray *)strings{
return array;
}

- (NSString *)stringByResolvingWildcardsInPath {
- (NSString *)subStringByResolvingWildcardsInPath {
NSRange index = [self rangeOfString:@"*"];
NSString *resolved;
if (index.location == NSNotFound) {
Expand All @@ -356,15 +356,23 @@ - (NSString *)stringByResolvingWildcardsInPath {

for (NSString *resolvedPathPart in contents) {
resolved = [[[basePath
stringByAppendingPathComponent:resolvedPathPart]
stringByAppendingPathComponent:remainingPath] stringByResolvingWildcardsInPath];
stringByAppendingPathComponent:resolvedPathPart]
stringByAppendingPathComponent:remainingPath] subStringByResolvingWildcardsInPath];
if (resolved != nil) {
return resolved;
}
}
return nil;
}

- (NSString *)stringByResolvingWildcardsInPath {
NSString *resolvedString = [self subStringByResolvingWildcardsInPath];
if (resolvedString == nil) {
return self;
}
return resolvedString;
}

- (NSString *)firstUnusedFilePath {
NSString *basePath = [self stringByDeletingPathExtension];
NSString *extension = [self pathExtension];
Expand Down
2 changes: 0 additions & 2 deletions Quicksilver/Quicksilver.xcodeproj/project.pbxproj
Expand Up @@ -1097,7 +1097,6 @@
6615228314F43355006FDCB4 /* PathWildcardsData */ = {isa = PBXFileReference; explicitFileType = folder; name = PathWildcardsData; path = Tests/TestData/PathWildcardsData; sourceTree = "<group>"; };
66448D9614F42790000FA2E2 /* QSFoundationTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QSFoundationTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
66448D9714F42790000FA2E2 /* QSFoundationTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "QSFoundationTests-Info.plist"; sourceTree = "<group>"; };
66448E1114F42A4E000FA2E2 /* TestPathWildcards.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestPathWildcards.h; path = "Tests/Tests-QSFoundation/TestPathWildcards.h"; sourceTree = "<group>"; };
66448E1214F42A4E000FA2E2 /* TestPathWildcards.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TestPathWildcards.m; path = "Tests/Tests-QSFoundation/TestPathWildcards.m"; sourceTree = "<group>"; };
666E45EE150225EA0034E60A /* QSCoreTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = QSCoreTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
666E45EF150225EA0034E60A /* QSCoreTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "QSCoreTests-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2040,7 +2039,6 @@
66448E0814F428E7000FA2E2 /* QSFoundationTests */ = {
isa = PBXGroup;
children = (
66448E1114F42A4E000FA2E2 /* TestPathWildcards.h */,
66448E1214F42A4E000FA2E2 /* TestPathWildcards.m */,
);
name = QSFoundationTests;
Expand Down
16 changes: 0 additions & 16 deletions Quicksilver/Tests/Tests-QSFoundation/TestPathWildcards.h

This file was deleted.

16 changes: 15 additions & 1 deletion Quicksilver/Tests/Tests-QSFoundation/TestPathWildcards.m
Expand Up @@ -6,9 +6,14 @@
// Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "TestPathWildcards.h"
#import <SenTestingKit/SenTestingKit.h>

#import "NSString_BLTRExtensions.h"

@interface TestPathWildcards : SenTestCase {
NSString *basePath;
}
@end

@implementation TestPathWildcards

Expand Down Expand Up @@ -58,5 +63,14 @@ -(void) testStandardizingAndNoWildcard{
STAssertTrue([resolvedPath isEqualToString:correctPath], @"Path not resolved correctly. Got %@ instead of %@", resolvedPath, correctPath);
}

-(void) testResolvedPathNotFound {
// issue 814
NSString *unresolvedPath = @"Contents/Resources/ExtraScripts/";
NSString *resolvedPath = [unresolvedPath stringByResolvingWildcardsInPath];
NSString *correctPath = unresolvedPath;

STAssertTrue([resolvedPath isEqualToString:correctPath], @"Path not resolved correctly. Got %@ instead of %@", resolvedPath, correctPath);
}


@end