Skip to content

Loading…

Crashing bug in replacePlaceholdersAndPrintStringFromBlock: #5

Merged
merged 1 commit into from

2 participants

@stury

The method stringByReplacingOccurrencesOfString:withString: throws an
exception if the withString: parameter is nil! Added checks to make
sure we have a value before trying to do the replacement.

A simple example to test this is to run the following code snippet as a terminal app:
NSString* hello = @"Hello, World!";
hello = [hello stringByReplacingOccurrencesOfString:@"World" withString:nil];

You'll get an exception because you've passed in a nil argument in the withString: parameter.

Scott Tury Crashing bug in replacePlaceholdersAndPrintStringFromBlock:
The method stringByReplacingOccurrencesOfString:withString: throws an
exception if the withString: parameter is nil!  Added checks to make
sure we have a value before trying to do the replacement.
8b3baec
@tomaz
Owner

Thanks!

@tomaz tomaz merged commit 2b5b5b4 into tomaz:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2014
  1. Crashing bug in replacePlaceholdersAndPrintStringFromBlock:

    Scott Tury committed
    The method stringByReplacingOccurrencesOfString:withString: throws an
    exception if the withString: parameter is nil!  Added checks to make
    sure we have a value before trying to do the replacement.
Showing with 4 additions and 2 deletions.
  1. +4 −2 GBCli/src/GBOptionsHelper.m
View
6 GBCli/src/GBOptionsHelper.m
@@ -325,8 +325,10 @@ - (void)replacePlaceholdersAndPrintStringFromBlock:(GBOptionStringBlock)block {
}
NSString *string = block();
string = [string stringByReplacingOccurrencesOfString:@"%APPNAME" withString:self.applicationNameFromBlockOrDefault];
- string = [string stringByReplacingOccurrencesOfString:@"%APPVERSION" withString:self.applicationVersionFromBlockOrNil];
- string = [string stringByReplacingOccurrencesOfString:@"%APPBUILD" withString:self.applicationBuildFromBlockOrNil];
+ if ( self.applicationVersionFromBlockOrNil )
+ string = [string stringByReplacingOccurrencesOfString:@"%APPVERSION" withString:self.applicationVersionFromBlockOrNil];
+ if ( self.applicationBuildFromBlockOrNil )
+ string = [string stringByReplacingOccurrencesOfString:@"%APPBUILD" withString:self.applicationBuildFromBlockOrNil];
printf("%s\n", string.UTF8String);
}
Something went wrong with that request. Please try again.