From a943a78640e1a3ebefa7db7db8549447a29fbc3b Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 30 Jul 2004 21:36:36 +0000 Subject: [PATCH] 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 --- ChangeLog | 12 ++++++++++++ Source/NSPropertyList.m | 38 ++++++++++++++++++++++++-------------- Source/NSString.m | 7 ++----- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f0505c4a..9d0135343 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-07-30 23:33 Alexander Malmberg + + * 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 * Headers/Foundation/*.h: Completed documentation of functions, types, diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index 5e8847cde..89abfda4b 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -41,6 +41,7 @@ #include "Foundation/NSUserDefaults.h" #include "Foundation/NSValue.h" #include "Foundation/NSDebug.h" +#include "GNUstepBase/Unicode.h" #include "GSPrivate.h" extern BOOL GSScanDouble(unichar*, unsigned, double*); @@ -356,17 +357,27 @@ static inline id parseQuotedString(pldata* pld) } else { - unsigned length = pld->pos - start - shrink; + unsigned length; unichar *chars; + unichar *temp = NULL; + unsigned int temp_length = 0; unsigned j; 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); escaped = 0; 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) { @@ -444,6 +455,9 @@ static inline id parseQuotedString(pldata* pld) } } + NSZoneFree(NSDefaultMallocZone(), temp); + length = k; + if (pld->key == NO && pld->opt == NSPropertyListMutableContainersAndLeaves) { @@ -1013,26 +1027,22 @@ GSPropertyListFromStringsFormat(NSString *string) NSMutableDictionary *dict; pldata _pld; pldata *pld = &_pld; - unsigned length = [string length]; + unsigned length; NSData *d; /* * An empty string is a nil property list. */ - if (length == 0) + if ([string length] == 0) { return nil; } - d = [string dataUsingEncoding: NSASCIIStringEncoding]; - if (d == nil) - { - [NSException raise: NSGenericException - format: @"Non-ascii data in string supposed to be property list"]; - } + d = [string dataUsingEncoding: NSUTF8StringEncoding]; + NSCAssert(d, @"Couldn't get utf8 data from string."); _pld.ptr = (unsigned char*)[d bytes]; _pld.pos = 0; - _pld.end = length; + _pld.end = [d length]; _pld.err = nil; _pld.lin = 0; _pld.opt = NSPropertyListImmutable; @@ -2203,7 +2213,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml, // It begins with '