Skip to content
Permalink
Browse files

Make it possible to use empty strings in content filters (#3083)

  • Loading branch information...
dmoagx committed Jun 15, 2019
1 parent 6c52588 commit 1ae3a5e37b2f54304003ce4ab2284d269d9cbba2
Showing with 21 additions and 54 deletions.
  1. +1 −1 Source/SPRuleFilterController.m
  2. +20 −53 Source/SPTableFilterParser.m
@@ -1388,7 +1388,7 @@ + (void)_writeFilterTree:(NSDictionary *)in toString:(NSMutableString *)out wrap
// SPTableFilterParser will return nil if it doesn't like the arguments and NSMutableString doesn't like nil
if(!sql) {
if(err) *err = [NSError errorWithDomain:SPErrorDomain code:3 userInfo:@{
NSLocalizedDescriptionKey: NSLocalizedString(@"No valid SQL expression could be generated. Make sure that you have filled in all required fields.", @"filter to sql conversion : internal error : SPTableFilterParser failed"),
NSLocalizedDescriptionKey: NSLocalizedString(@"No valid SQL expression could be generated. Perhaps the filter definition is invalid.", @"filter to sql conversion : internal error : SPTableFilterParser failed"),
}];
[parser release];
return;
@@ -72,33 +72,13 @@ - (void)dealloc

- (NSString *)filterString
{
NSString *filterString;

// argument if Filter requires only one argument
NSMutableString *argument = [[NSMutableString alloc] initWithString:(_argument? _argument : @"")];

// If the filter field is empty and the selected filter does not require
// only one argument, then no filtering is required - return nil.
if (![argument length] && numberOfArguments == 1) {
[argument release];
return nil;
}

// arguments if Filter requires two arguments
NSMutableString *firstBetweenArgument = [[NSMutableString alloc] initWithString:(_firstBetweenArgument? _firstBetweenArgument : @"")];
NSMutableString *secondBetweenArgument = [[NSMutableString alloc] initWithString:(_secondBetweenArgument? _secondBetweenArgument : @"")];

// If filter requires two arguments and either of the argument fields are empty
// return nil.
if (numberOfArguments == 2) {
if (([firstBetweenArgument length] == 0) || ([secondBetweenArgument length] == 0)) {
[argument release];
[firstBetweenArgument release];
[secondBetweenArgument release];
return nil;
}
}

// Retrieve actual WHERE clause
NSMutableString *clause = [[NSMutableString alloc] init];
[clause setString:_clause];
@@ -135,40 +115,27 @@ - (NSString *)filterString
}

// Construct the filter string according the required number of arguments

if(suppressLeadingTablePlaceholder) {
if (numberOfArguments == 2) {
filterString = [NSString stringWithFormat:clause,
[[self class] escapeFilterArgument:firstBetweenArgument againstClause:clause],
[[self class] escapeFilterArgument:secondBetweenArgument againstClause:clause]];
} else if (numberOfArguments == 1) {
filterString = [NSString stringWithFormat:clause, [[self class] escapeFilterArgument:argument againstClause:clause]];
} else {
filterString = [NSString stringWithString:clause];
if(numberOfArguments > 2) {
SPLog(@"Filter with more than 2 arguments is not yet supported.");
NSBeep();
}
}
NSMutableString *filterString = [NSMutableString string];

if(!suppressLeadingTablePlaceholder) {
[filterString appendFormat:@"%@ ",[_currentField backtickQuotedString]];
}

NSUInteger numArgs = numberOfArguments;
if(numArgs > 2) {
SPLog(@"Filter with more than 2 arguments is not yet supported.");
NSBeep();
numArgs = 2;
}

if (numArgs == 2) {
[filterString appendFormat:clause,
[[self class] escapeFilterArgument:firstBetweenArgument againstClause:clause],
[[self class] escapeFilterArgument:secondBetweenArgument againstClause:clause]];
} else if (numArgs == 1) {
[filterString appendFormat:clause, [[self class] escapeFilterArgument:argument againstClause:clause]];
} else {
if (numberOfArguments == 2) {
filterString = [NSString stringWithFormat:@"%@ %@",
[_currentField backtickQuotedString],
[NSString stringWithFormat:clause,
[[self class] escapeFilterArgument:firstBetweenArgument againstClause:clause],
[[self class] escapeFilterArgument:secondBetweenArgument againstClause:clause]]];
} else if (numberOfArguments == 1) {
filterString = [NSString stringWithFormat:@"%@ %@",
[_currentField backtickQuotedString],
[NSString stringWithFormat:clause, [[self class] escapeFilterArgument:argument againstClause:clause]]];
} else {
filterString = [NSString stringWithFormat:@"%@ %@",
[_currentField backtickQuotedString], clause];
if(numberOfArguments > 2) {
SPLog(@"Filter with more than 2 arguments is not yet supported.");
NSBeep();
}
}
[filterString appendString:clause];
}

[argument release];

0 comments on commit 1ae3a5e

Please sign in to comment.
You can’t perform that action at this time.