Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
astralbodies committed Mar 21, 2014
2 parents 8229807 + 35ce25e commit 1b7d521
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions WPXMLRPC/WPStringUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
@implementation WPStringUtils

+ (NSString *)unescapedStringWithString:(NSString *)aString {
if (!aString) {
return nil;
}

NSMutableString *string = [NSMutableString stringWithString:aString];

[string replaceOccurrencesOfString:@""" withString:@"\"" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"'" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"9" withString:@"'" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
Expand All @@ -36,19 +40,23 @@ + (NSString *)unescapedStringWithString:(NSString *)aString {
[string replaceOccurrencesOfString:@">" withString:@">" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"&lt;" withString:@"<" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"&amp;" withString:@"&" options:NSLiteralSearch range:NSMakeRange(0, [string length])];

return [NSString stringWithString:string];
}

+ (NSString *)escapedStringWithString:(NSString *)aString {
if (!aString) {
return nil;
}

NSMutableString *string = [NSMutableString stringWithString:aString];

// NOTE:we use unicode entities instead of &amp; &gt; &lt; etc. since some hosts (powweb, fatcow, and similar)
// have a weird PHP/libxml2 combination that ignores regular entities
[string replaceOccurrencesOfString:@"&" withString:@"&#38;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@">" withString:@"&#62;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];
[string replaceOccurrencesOfString:@"<" withString:@"&#60;" options:NSLiteralSearch range:NSMakeRange(0, [string length])];

return [NSString stringWithString:string];
}

Expand Down

0 comments on commit 1b7d521

Please sign in to comment.