Skip to content

Commit 1b7d521

Browse files
committed
2 parents 8229807 + 35ce25e commit 1b7d521

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

WPXMLRPC/WPStringUtils.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
@implementation WPStringUtils
2727

2828
+ (NSString *)unescapedStringWithString:(NSString *)aString {
29+
if (!aString) {
30+
return nil;
31+
}
32+
2933
NSMutableString *string = [NSMutableString stringWithString:aString];
30-
34+
3135
[string replaceOccurrencesOfString:@""" withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
3236
[string replaceOccurrencesOfString:@"'" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
3337
[string replaceOccurrencesOfString:@"9" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
@@ -36,19 +40,23 @@ + (NSString *)unescapedStringWithString:(NSString *)aString {
3640
[string replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
3741
[string replaceOccurrencesOfString:@"&lt;" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
3842
[string replaceOccurrencesOfString:@"&amp;" withString:@"&" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
39-
43+
4044
return [NSString stringWithString:string];
4145
}
4246

4347
+ (NSString *)escapedStringWithString:(NSString *)aString {
48+
if (!aString) {
49+
return nil;
50+
}
51+
4452
NSMutableString *string = [NSMutableString stringWithString:aString];
45-
53+
4654
// NOTE:we use unicode entities instead of &amp; &gt; &lt; etc. since some hosts (powweb, fatcow, and similar)
4755
// have a weird PHP/libxml2 combination that ignores regular entities
4856
[string replaceOccurrencesOfString:@"&" withString:@"&#38;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
4957
[string replaceOccurrencesOfString:@">" withString:@"&#62;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
5058
[string replaceOccurrencesOfString:@"<" withString:@"&#60;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
51-
59+
5260
return [NSString stringWithString:string];
5361
}
5462

0 commit comments

Comments
 (0)