Fix error in adding percent escapes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23622 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-09-26 11:16:06 +00:00
parent 6e89831563
commit 452976f6a3
3 changed files with 45 additions and 48 deletions

View file

@ -1,3 +1,9 @@
2006-09-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: ([stringByAddingPercentEscapesUsingEncoding:])
Fix to escape '@' (in fact anything not unreserved acording to
RFC2396)
2006-09-21 Richard Frith-Macdonald <rfm@gnu.org> 2006-09-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSProcessInfo.m: ([-operatingSystemName]) conform to * Source/NSProcessInfo.m: ([-operatingSystemName]) conform to

View file

@ -145,7 +145,8 @@ static NSString *gnustepUserDir = nil;
static NSString *gnustepUserHome = nil; static NSString *gnustepUserHome = nil;
static NSString *gnustepUserDefaultsDir = 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 *tempDir = nil; /* user's temporary directory */
static NSString *osSysApps = nil; static NSString *osSysApps = nil;
@ -969,6 +970,7 @@ GSSetUserName(NSString *aName)
* Reset things as new user * Reset things as new user
*/ */
ASSIGN(theUserName, aName); ASSIGN(theUserName, aName);
DESTROY(theFullUserName);
InitialisePathUtilities(); InitialisePathUtilities();
[NSUserDefaults resetStandardUserDefaults]; [NSUserDefaults resetStandardUserDefaults];
@ -980,7 +982,8 @@ GSSetUserName(NSString *aName)
* Under unix-like systems, the name associated with the current * Under unix-like systems, the name associated with the current
* effective user ID is used.<br/ > * effective user ID is used.<br/ >
* Under ms-windows, the 'LOGNAME' environment is used, or if that fails, the * 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.<br />
* Raises an exception on failure.
*/ */
/* NOTE FOR DEVELOPERS. /* NOTE FOR DEVELOPERS.
* If you change the behavior of this method you must also change * If you change the behavior of this method you must also change
@ -1129,20 +1132,32 @@ NSHomeDirectoryForUser(NSString *loginName)
NSString * NSString *
NSFullUserName(void) NSFullUserName(void)
{ {
if (theFullUserName == nil)
{
NSString *userName = NSUserName();
#if defined(__MINGW32__) #if defined(__MINGW32__)
/* FIXME: Win32 way to get full user name via Net API */ struct _USER_INFO_2 *userInfo;
return NSUserName();
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 #else
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
struct passwd *pw; struct passwd *pw;
pw = getpwnam([NSUserName() cString]); pw = getpwnam([NSUserName() cString]);
return [NSString stringWithCString: pw->pw_gecos]; userName = [NSString stringWithCString: pw->pw_gecos];
#else #else
NSLog(@"Warning: NSFullUserName not implemented\n"); NSLog(@"Warning: NSFullUserName not implemented\n");
return NSUserName(); userName = NSUserName();
#endif /* HAVE_PWD_H */ #endif /* HAVE_PWD_H */
#endif /* defined(__Win32__) else */ #endif /* defined(__Win32__) else */
ASSIGN(theFullUserName, userName);
}
return theFullUserName;
} }
/** /**

View file

@ -1328,6 +1328,9 @@ handle_printf_atsign (FILE *stream,
* Constructs a new ASCII string which is a representation of the receiver * Constructs a new ASCII string which is a representation of the receiver
* in which characters are escaped where necessary in order to produce a * in which characters are escaped where necessary in order to produce a
* legal URL.<br /> * legal URL.<br />
* 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 ("-_.!~*'()").<br />
* Returns nil if the receiver cannot be represented using the specified * Returns nil if the receiver cannot be represented using the specified
* encoding. * encoding.
*/ */
@ -1351,46 +1354,19 @@ handle_printf_atsign (FILE *stream,
unsigned int hi; unsigned int hi;
unsigned int lo; unsigned int lo;
switch (c) if (isalpha(c) || isdigit(c)
|| c == '-' || c == '_' || c == '.' || c == '!' || c == '~'
|| c == '*' || c == '\'' || c == '(' || c == ')')
{ {
case ',': dst[dpos++] = c;
case ';': }
case '"': else
case '\'': {
case '&': dst[dpos++] = '%';
case '=': hi = (c & 0xf0) >> 4;
case '(': dst[dpos++] = (hi > 9) ? 'A' + hi - 10 : '0' + hi;
case ')': lo = (c & 0x0f);
case '<': dst[dpos++] = (lo > 9) ? 'A' + lo - 10 : '0' + lo;
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;
} }
} }
[d setLength: dpos]; [d setLength: dpos];