aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/TableContent.h2
-rw-r--r--Source/TableContent.m34
2 files changed, 33 insertions, 3 deletions
diff --git a/Source/TableContent.h b/Source/TableContent.h
index a498189b..0993110a 100644
--- a/Source/TableContent.h
+++ b/Source/TableContent.h
@@ -129,4 +129,6 @@
- (void) storeCurrentDetailsForRestoration;
- (void) clearDetailsToRestore;
+- (NSString *)escapeFilterArgument:(NSString *)argument againstClause:(NSString *)clause;
+
@end
diff --git a/Source/TableContent.m b/Source/TableContent.m
index ed9cf237..ccf26181 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -568,7 +568,7 @@
[clause setString:[filter objectForKey:@"Clause"]];
// Escape % sign
- [clause replaceOccurrencesOfRegex:@"%"withString:@"%%"];
+ [clause replaceOccurrencesOfRegex:@"%" withString:@"%%"];
[clause flushCachedRegexData];
// Replace placeholder ${} by %@
@@ -597,11 +597,13 @@
if (numberOfArguments == 2) {
filterString = [NSString stringWithFormat:@"%@ %@",
[[fieldField titleOfSelectedItem] backtickQuotedString],
- [NSString stringWithFormat:clause, firstBetweenArgument, secondBetweenArgument]];
+ [NSString stringWithFormat:clause,
+ [self escapeFilterArgument:firstBetweenArgument againstClause:clause],
+ [self escapeFilterArgument:secondBetweenArgument againstClause:clause]]];
} else if (numberOfArguments == 1) {
filterString = [NSString stringWithFormat:@"%@ %@",
[[fieldField titleOfSelectedItem] backtickQuotedString],
- [NSString stringWithFormat:clause, argument]];
+ [NSString stringWithFormat:clause, [self escapeFilterArgument:argument againstClause:clause]]];
} else {
filterString = [NSString stringWithFormat:@"%@ %@",
[[fieldField titleOfSelectedItem] backtickQuotedString],
@@ -621,6 +623,32 @@
return filterString;
}
+- (NSString *)escapeFilterArgument:(NSString *)argument againstClause:(NSString *)clause
+{
+
+ NSMutableString *arg = [[NSMutableString alloc] init];
+ [arg setString:argument];
+
+ [arg replaceOccurrencesOfRegex:@"(\\\\)(?![nrt])" withString:@"\\\\\\\\\\\\\\\\"];
+ [arg flushCachedRegexData];
+ [arg replaceOccurrencesOfRegex:@"(\\\\)(?=[nrt])" withString:@"\\\\\\"];
+ [arg flushCachedRegexData];
+
+ // Get quote sign for escaping - this should work for 99% of all cases
+ NSString *quoteSign = [clause stringByMatching:@"([\"'])[^\\1]*?%@[^\\1]*?\\1" capture:1L];
+ // Esape argument
+ if(quoteSign != nil && [quoteSign length] == 1) {
+ [arg replaceOccurrencesOfRegex:[NSString stringWithFormat:@"(%@)", quoteSign] withString:@"\\\\$1"];
+ [arg flushCachedRegexData];
+ }
+ if([clause isMatchedByRegex:@"(?i)\\blike\\b.*?%(?!@)"]) {
+ NSLog(@"asdas", _cmd);
+ [arg replaceOccurrencesOfRegex:@"([_%])" withString:@"\\\\$1"];
+ [arg flushCachedRegexData];
+ }
+ return [arg autorelease];
+}
+
/*
* Update the table count/selection text
*/