diff --git a/ChangeLog b/ChangeLog index 346740824..6574329dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-09-26 Richard Frith-Macdonald + + * Source/NSString.m: ([stringByAddingPercentEscapesUsingEncoding:]) + Fix to escape '@' (in fact anything not unreserved acording to + RFC2396) + 2006-09-21 Richard Frith-Macdonald * Source/NSProcessInfo.m: ([-operatingSystemName]) conform to diff --git a/Source/NSPathUtilities.m b/Source/NSPathUtilities.m index a796fc5a4..7d516e7ff 100644 --- a/Source/NSPathUtilities.m +++ b/Source/NSPathUtilities.m @@ -145,7 +145,8 @@ static NSString *gnustepUserDir = nil; static NSString *gnustepUserHome = nil; static NSString *gnustepUserDefaultsDir = nil; -static NSString *theUserName = nil; /* The user's login name */ +static NSString *theUserName = nil; /* The user's login name */ +static NSString *theFullUserName = nil; /* The user's full login name */ static NSString *tempDir = nil; /* user's temporary directory */ static NSString *osSysApps = nil; @@ -969,6 +970,7 @@ GSSetUserName(NSString *aName) * Reset things as new user */ ASSIGN(theUserName, aName); + DESTROY(theFullUserName); InitialisePathUtilities(); [NSUserDefaults resetStandardUserDefaults]; @@ -980,7 +982,8 @@ GSSetUserName(NSString *aName) * Under unix-like systems, the name associated with the current * effective user ID is used.
* Under ms-windows, the 'LOGNAME' environment is used, or if that fails, the - * GetUserName() call is used to find the user name. + * GetUserName() call is used to find the user name.
+ * Raises an exception on failure. */ /* NOTE FOR DEVELOPERS. * If you change the behavior of this method you must also change @@ -1129,20 +1132,32 @@ NSHomeDirectoryForUser(NSString *loginName) NSString * NSFullUserName(void) { + if (theFullUserName == nil) + { + NSString *userName = NSUserName(); #if defined(__MINGW32__) - /* FIXME: Win32 way to get full user name via Net API */ - return NSUserName(); + struct _USER_INFO_2 *userInfo; + + NSString *userName = NSUserName(); + if (NetUserGetInfo(NULL, UniBuf(userName), 2, (LPBYTE*)&userInfo) == 0) + { + userName = [NSString stringWithCharacters: userInfo->usri2_full_name + length: wcslen(userInfo->usri2_full_name)]; + } #else #ifdef HAVE_PWD_H - struct passwd *pw; + struct passwd *pw; - pw = getpwnam([NSUserName() cString]); - return [NSString stringWithCString: pw->pw_gecos]; + pw = getpwnam([NSUserName() cString]); + userName = [NSString stringWithCString: pw->pw_gecos]; #else - NSLog(@"Warning: NSFullUserName not implemented\n"); - return NSUserName(); + NSLog(@"Warning: NSFullUserName not implemented\n"); + userName = NSUserName(); #endif /* HAVE_PWD_H */ #endif /* defined(__Win32__) else */ + ASSIGN(theFullUserName, userName); + } + return theFullUserName; } /** diff --git a/Source/NSString.m b/Source/NSString.m index d7396cbe5..bec1fde06 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -1328,6 +1328,9 @@ handle_printf_atsign (FILE *stream, * Constructs a new ASCII string which is a representation of the receiver * in which characters are escaped where necessary in order to produce a * legal URL.
+ * Escaping is done for any character which is not 'unreserved' according + * to RFC2396. The unreserved characters are letters, digits, and the + * set of 'marks' characters ("-_.!~*'()").
* Returns nil if the receiver cannot be represented using the specified * encoding. */ @@ -1351,46 +1354,19 @@ handle_printf_atsign (FILE *stream, unsigned int hi; unsigned int lo; - switch (c) + if (isalpha(c) || isdigit(c) + || c == '-' || c == '_' || c == '.' || c == '!' || c == '~' + || c == '*' || c == '\'' || c == '(' || c == ')') { - case ',': - case ';': - case '"': - case '\'': - case '&': - case '=': - case '(': - case ')': - case '<': - case '>': - case '?': - case '#': - case '{': - case '}': - case '%': - case ' ': - case '+': - dst[dpos++] = '%'; - hi = (c & 0xf0) >> 4; - dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi; - lo = (c & 0x0f); - dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo; - break; - - default: - if (c < ' ' || c > 127) - { - dst[dpos++] = '%'; - hi = (c & 0xf0) >> 4; - dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi; - lo = (c & 0x0f); - dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo; - } - else - { - dst[dpos++] = c; - } - break; + dst[dpos++] = c; + } + else + { + dst[dpos++] = '%'; + hi = (c & 0xf0) >> 4; + dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi; + lo = (c & 0x0f); + dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo; } } [d setLength: dpos];