mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 09:31:07 +00:00
Fix handling of plists and strings files in non-ascii encodings.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@19805 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0b0d82b281
commit
a943a78640
3 changed files with 38 additions and 19 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
2004-07-30 23:33 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
* Source/NSPropertyList.m (parseQuotedString): Handle utf8 data
|
||||||
|
properly.
|
||||||
|
(GSPropertyListFromStringsFormat): Convert the string to utf8 data,
|
||||||
|
not ascii. Set length from the data.
|
||||||
|
(+propertyListFromData:mutabilityOption:format:errorDescription:): Fix
|
||||||
|
a typo in an error message. Set format for normal plist with
|
||||||
|
extensions to NSPropertyListGNUstepFormat.
|
||||||
|
* Source/NSString.m (-propertyList): Convert the string to utf8 data,
|
||||||
|
not ascii.
|
||||||
|
|
||||||
2004-07-20 Adrian Robert <arobert@cogsci.ucsd.edu>
|
2004-07-20 Adrian Robert <arobert@cogsci.ucsd.edu>
|
||||||
|
|
||||||
* Headers/Foundation/*.h: Completed documentation of functions, types,
|
* Headers/Foundation/*.h: Completed documentation of functions, types,
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "Foundation/NSUserDefaults.h"
|
#include "Foundation/NSUserDefaults.h"
|
||||||
#include "Foundation/NSValue.h"
|
#include "Foundation/NSValue.h"
|
||||||
#include "Foundation/NSDebug.h"
|
#include "Foundation/NSDebug.h"
|
||||||
|
#include "GNUstepBase/Unicode.h"
|
||||||
|
|
||||||
#include "GSPrivate.h"
|
#include "GSPrivate.h"
|
||||||
extern BOOL GSScanDouble(unichar*, unsigned, double*);
|
extern BOOL GSScanDouble(unichar*, unsigned, double*);
|
||||||
|
@ -356,17 +357,27 @@ static inline id parseQuotedString(pldata* pld)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned length = pld->pos - start - shrink;
|
unsigned length;
|
||||||
unichar *chars;
|
unichar *chars;
|
||||||
|
unichar *temp = NULL;
|
||||||
|
unsigned int temp_length = 0;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
unsigned k;
|
unsigned k;
|
||||||
|
|
||||||
|
if (!GSToUnicode(&temp, &temp_length, &pld->ptr[start],
|
||||||
|
pld->pos - start, NSUTF8StringEncoding,
|
||||||
|
NSDefaultMallocZone(), 0))
|
||||||
|
{
|
||||||
|
pld->err = @"invalid utf8 data while parsing quoted string";
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
length = temp_length - shrink;
|
||||||
chars = NSZoneMalloc(NSDefaultMallocZone(), sizeof(unichar) * length);
|
chars = NSZoneMalloc(NSDefaultMallocZone(), sizeof(unichar) * length);
|
||||||
escaped = 0;
|
escaped = 0;
|
||||||
hex = NO;
|
hex = NO;
|
||||||
for (j = start, k = 0; j < pld->pos; j++)
|
for (j = 0, k = 0; j < temp_length; j++)
|
||||||
{
|
{
|
||||||
unsigned char c = pld->ptr[j];
|
unichar c = temp[j];
|
||||||
|
|
||||||
if (escaped)
|
if (escaped)
|
||||||
{
|
{
|
||||||
|
@ -444,6 +455,9 @@ static inline id parseQuotedString(pldata* pld)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), temp);
|
||||||
|
length = k;
|
||||||
|
|
||||||
if (pld->key ==
|
if (pld->key ==
|
||||||
NO && pld->opt == NSPropertyListMutableContainersAndLeaves)
|
NO && pld->opt == NSPropertyListMutableContainersAndLeaves)
|
||||||
{
|
{
|
||||||
|
@ -1013,26 +1027,22 @@ GSPropertyListFromStringsFormat(NSString *string)
|
||||||
NSMutableDictionary *dict;
|
NSMutableDictionary *dict;
|
||||||
pldata _pld;
|
pldata _pld;
|
||||||
pldata *pld = &_pld;
|
pldata *pld = &_pld;
|
||||||
unsigned length = [string length];
|
unsigned length;
|
||||||
NSData *d;
|
NSData *d;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An empty string is a nil property list.
|
* An empty string is a nil property list.
|
||||||
*/
|
*/
|
||||||
if (length == 0)
|
if ([string length] == 0)
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = [string dataUsingEncoding: NSASCIIStringEncoding];
|
d = [string dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
if (d == nil)
|
NSCAssert(d, @"Couldn't get utf8 data from string.");
|
||||||
{
|
|
||||||
[NSException raise: NSGenericException
|
|
||||||
format: @"Non-ascii data in string supposed to be property list"];
|
|
||||||
}
|
|
||||||
_pld.ptr = (unsigned char*)[d bytes];
|
_pld.ptr = (unsigned char*)[d bytes];
|
||||||
_pld.pos = 0;
|
_pld.pos = 0;
|
||||||
_pld.end = length;
|
_pld.end = [d length];
|
||||||
_pld.err = nil;
|
_pld.err = nil;
|
||||||
_pld.lin = 0;
|
_pld.lin = 0;
|
||||||
_pld.opt = NSPropertyListImmutable;
|
_pld.opt = NSPropertyListImmutable;
|
||||||
|
@ -2203,7 +2213,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||||
// It begins with '<?' so it is xml
|
// It begins with '<?' so it is xml
|
||||||
format = NSPropertyListXMLFormat_v1_0;
|
format = NSPropertyListXMLFormat_v1_0;
|
||||||
#else
|
#else
|
||||||
error = @"XML format not supported ... XML support notn present.";
|
error = @"XML format not supported ... XML support not present.";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2261,7 +2271,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||||
if (_pld.old == NO)
|
if (_pld.old == NO)
|
||||||
{
|
{
|
||||||
// Found some modern GNUstep extension in data.
|
// Found some modern GNUstep extension in data.
|
||||||
format = NSPropertyListGNUstepBinaryFormat;
|
format = NSPropertyListGNUstepFormat;
|
||||||
}
|
}
|
||||||
if (_pld.err != nil)
|
if (_pld.err != nil)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4584,11 +4584,8 @@ handle_printf_atsign (FILE *stream,
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
if ((data = [self dataUsingEncoding: NSASCIIStringEncoding]) == nil)
|
data = [self dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
{
|
NSAssert(data, @"Couldn't get utf8 data from string.");
|
||||||
[NSException raise: NSGenericException
|
|
||||||
format: @"Non-ascii data in string supposed to be property list"];
|
|
||||||
}
|
|
||||||
|
|
||||||
result = [NSPropertyListSerialization
|
result = [NSPropertyListSerialization
|
||||||
propertyListFromData: data
|
propertyListFromData: data
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue