From 0590540ba0ea0760d9767b2a282510a5d7531ba7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 16 May 2009 23:53:21 -0400 Subject: [PATCH] More fixes for paths with spaces. We can't use single quotes to pass path names, so create a new method to escape them. * Source/GDBpConnection.m: (escapedURIPath): New private method that takes a path and returns a safe file:// URI (addBreakpoint:): Use -[escapedURIPath:] (createStackFrame:): Don't pass the escaped path to the frame, keep it internally --- Source/GDBpConnection.m | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index 07efb86..f8463f2 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -27,6 +27,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; - (StackFrame*)createStackFrame:(int)depth; - (StackFrame*)createCurrentStackFrame; - (void)updateStatus; +- (NSString*)escapedURIPath:(NSString*)path; @end @implementation GDBpConnection @@ -250,7 +251,8 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; if (!connected) return; - NSString* cmd = [self createCommand:[NSString stringWithFormat:@"breakpoint_set -t line -f '%@' -n %i", [bp transformedPath], [bp line]]]; + NSString* file = [self escapedURIPath:[bp transformedPath]]; + NSString* cmd = [self createCommand:[NSString stringWithFormat:@"breakpoint_set -t line -f %@ -n %i", file, [bp line]]]; [socket send:cmd]; NSXMLDocument* info = [self processData:[socket receive]]; [bp setDebuggerId:[[[[info rootElement] attributeForName:@"id"] stringValue] intValue]]; @@ -356,8 +358,8 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; // get the source NSString* filename = [[xmlframe attributeForName:@"filename"] stringValue]; - filename = [filename stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]; // escape % in URL chars - [socket send:[self createCommand:[NSString stringWithFormat:@"source -f %@", filename]]]; + NSString* escapedFilename = [filename stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]; // escape % in URL chars + [socket send:[self createCommand:[NSString stringWithFormat:@"source -f %@", escapedFilename]]]; NSString* source = [[[self processData:[socket receive]] rootElement] value]; // decode base64 // create stack frame @@ -398,4 +400,26 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; } } +/** + * Given a file path, this returns a file:// URI and escapes any spaces for the + * debugger engine. + */ +- (NSString*)escapedURIPath:(NSString*)path +{ + // Custon GDBp paths are fine. + if ([[path substringToIndex:4] isEqualToString:@"gdbp"]) + return path; + + // Create a temporary URL that will escape all the nasty characters. + NSURL* url = [NSURL fileURLWithPath:path]; + NSString* urlString = [url absoluteString]; + + // Remove the host because this is a file:// URL; + urlString = [urlString stringByReplacingOccurrencesOfString:[url host] withString:@""]; + + // Escape % for use in printf-style NSString formatters. + urlString = [urlString stringByReplacingOccurrencesOfString:@"%" withString:@"%%"]; + return urlString; +} + @end -- 2.22.5