Skip to content

Commit 41ce3fe

Browse files
committed
Sanitize filenames before using a part of the test method
1 parent a67d4ca commit 41ce3fe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Quick/QuickSpec.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,19 @@ + (SEL)addInstanceMethodForExample:(Example *)example {
103103
currentSpec = self;
104104
[example run];
105105
});
106+
NSCharacterSet *characterSet = [NSCharacterSet alphanumericCharacterSet];
107+
NSMutableString *sanitizedFileName = [NSMutableString string];
108+
for (NSUInteger i = 0; i < example.callsite.file.length; i++) {
109+
unichar ch = [example.callsite.file characterAtIndex:i];
110+
if ([characterSet characterIsMember:ch]) {
111+
[sanitizedFileName appendFormat:@"%c", ch];
112+
}
113+
}
114+
106115
const char *types = [[NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)] UTF8String];
107116
NSString *selectorName = [NSString stringWithFormat:@"%@_%@_%ld",
108117
example.name.qck_selectorName,
109-
example.callsite.file,
118+
sanitizedFileName,
110119
(long)example.callsite.line];
111120
SEL selector = NSSelectorFromString(selectorName);
112121
class_addMethod(self, selector, implementation, types);

0 commit comments

Comments
 (0)