From cb6555b9e249302db4ebfb3bfc6c3f8d1cb66de9 Mon Sep 17 00:00:00 2001 From: Daniele Orlando Date: Wed, 1 Jul 2015 00:40:28 +0200 Subject: [PATCH] QLColorCode handles file paths with single quote ('). colorize.sh was failing trying to generate a preview for files with a single quote in their name (or path). Example: The preview command for file "l'altro.sh" was generated like this: 'colorize.sh' '' '/l'altro.sh' '0' resulting in: qlmanage[66236]: QLColorCode: colorize.sh failed with exit code 2. --- Common.m | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Common.m b/Common.m index 70e5d8e..335f559 100644 --- a/Common.m +++ b/Common.m @@ -64,7 +64,7 @@ n8log(@"url = %@", url); NSString *targetEsc = pathOfURL(url); n8log(@"targetEsc = %@", targetEsc); - + // Set up preferences NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *env = [NSMutableDictionary dictionaryWithDictionary: @@ -81,10 +81,16 @@ @"UTF-8", @"textEncoding", @"UTF-8", @"webkitTextEncoding", nil]]; [env addEntriesFromDictionary:[defaults persistentDomainForName:myDomain]]; - + + NSMutableString *targetEscaped = [NSMutableString stringWithString:targetEsc]; + [targetEscaped replaceOccurrencesOfString:@"'" + withString:@"'\\''" + options:0 + range:NSMakeRange(0, [targetEscaped length])]; + NSString *cmd = [NSString stringWithFormat: @"'%@/colorize.sh' '%@' '%@' %s", - rsrcEsc, rsrcEsc, targetEsc, thumbnail ? "1" : "0"]; + rsrcEsc, rsrcEsc, targetEscaped , thumbnail ? "1" : "0"]; n8log(@"cmd = %@", cmd); output = runTask(cmd, env, status);