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:
Richard Frith-MacDonald 2006-09-26 11:16:06 +00:00
parent a80f6eb379
commit 273f267524
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>
* Source/NSProcessInfo.m: ([-operatingSystemName]) conform to

View file

@ -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.<br/ >
* 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.
* 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;
}
/**

View file

@ -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.<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
* 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];