Skip to content

Commit

Permalink
Merge pull request #324 from the-nic/fix-5416
Browse files Browse the repository at this point in the history
(fix) NSString+Utilities: Fix safeStringByEscapingXMLString on gnuste…
  • Loading branch information
WoodySlum committed Oct 4, 2022
2 parents 04dd78d + 3b3e019 commit d5ad0dd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions SoObjects/SOGo/NSString+Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (NSString *) urlWithoutParameters;
{
NSRange r;
NSString *newUrl;

r = [self rangeOfString:@"?" options: NSBackwardsSearch];
if (r.length > 0)
newUrl = [self substringToIndex: NSMaxRange (r) - 1];
Expand Down Expand Up @@ -187,7 +187,7 @@ - (void) _handleURLs: (NSMutableString *) selfCopy
[selfCopy replaceCharactersInRange: *rangePtr
withString: newUrlText];
offset += ([newUrlText length] - [urlText length]);

// Add range for further substitutions
currentUrlRange = NSMakeRange (rangePtr->location, [newUrlText length]);
[ranges addNonNSObject: &currentUrlRange
Expand Down Expand Up @@ -379,7 +379,7 @@ - (NSString *) safeStringByEscapingXMLString: (BOOL) encodeCR

if ([self length] == 0) return @"";

data = [self dataUsingEncoding: NSUTF32StringEncoding];
data = [self dataUsingEncoding: NSUTF32LittleEndianStringEncoding];
chars = [data bytes];
len = [data length]/4;

Expand Down Expand Up @@ -456,7 +456,7 @@ - (NSString *) safeStringByEscapingXMLString: (BOOL) encodeCR

self = [[NSString alloc] initWithBytesNoCopy: buf
length: (j*sizeof(wchar_t))
encoding: NSUTF32StringEncoding
encoding: NSUTF32LittleEndianStringEncoding
freeWhenDone: YES];
return [self autorelease];
}
Expand Down Expand Up @@ -698,7 +698,7 @@ - (int) timeValue
}
else
time = -1;

return time;
}

Expand Down Expand Up @@ -806,7 +806,7 @@ - (NSString *) stringByReplacingPrefix: (NSString *) oldPrefix
newString = [NSString stringWithFormat: @"%@%@",
newPrefix,
[self substringFromIndex: oldPrefixLength]];

return newString;
}

Expand All @@ -817,7 +817,7 @@ - (NSString *) encryptWithKey: (NSString *) theKey
NSString *result;
NSUInteger i, passLength, theKeyLength, keyLength;
unichar p, k, e;

if ([theKey length] > 0)
{
// The length of the key must be greater (or equal) than
Expand All @@ -832,7 +832,7 @@ - (NSString *) encryptWithKey: (NSString *) theKey
[key appendString: theKey];
keyLength += theKeyLength;
}

encryptedPassword = [NSMutableData data];
for (i = 0; i < passLength; i++)
{
Expand All @@ -841,15 +841,15 @@ - (NSString *) encryptWithKey: (NSString *) theKey
e = p ^ k;
[encryptedPassword appendBytes: (void *)&e length: 2];
}

result = [encryptedPassword stringByEncodingBase64];
}
else
result = nil;

return result;
}

- (NSString *) decryptWithKey: (NSString *) theKey
{
NSMutableString *result;
Expand All @@ -858,7 +858,7 @@ - (NSString *) decryptWithKey: (NSString *) theKey
unichar *decryptedPassword;
NSUInteger i, theKeyLength, keyLength, decodedLength;
unichar p, k;

if ([theKey length] > 0)
{
decoded = [self dataByDecodingBase64];
Expand All @@ -870,13 +870,13 @@ - (NSString *) decryptWithKey: (NSString *) theKey
keyLength = 0;
decodedLength = ([decoded length] / 2); /* 1 unichar = 2 bytes/char */
theKeyLength = [theKey length];

while (keyLength < decodedLength)
{
[key appendString: theKey];
keyLength += theKeyLength;
}

result = [NSMutableString string];
for (i = 0; i < decodedLength; i++)
{
Expand Down

0 comments on commit d5ad0dd

Please sign in to comment.