@@ -31,10 +31,11 @@ # import "OFFile.h" #endif #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" +#import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFUnboundPrefixException.h" typedef void (*state_function_t)(id, SEL); static SEL selectors[OF_XMLPARSER_NUM_STATES]; @@ -57,12 +58,12 @@ objc_autoreleasePoolPop(pool); } } static OFString* -transformString(OFDataArray *buffer, size_t cut, bool unescape, - id delegate) +transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut, + bool unescape) { char *items; size_t i, length; bool hasEntities = false; OFString *ret; @@ -85,12 +86,18 @@ } ret = [OFString stringWithUTF8String: items length: length]; - if (unescape && hasEntities) - return [ret stringByXMLUnescapingWithDelegate: delegate]; + if (unescape && hasEntities) { + @try { + return [ret stringByXMLUnescapingWithDelegate: parser]; + } @catch (OFInvalidFormatException *e) { + @throw [OFMalformedXMLException + exceptionWithParser: parser]; + } + } return ret; } static OFString* @@ -349,11 +356,11 @@ if ((length = _i - _last) > 0) appendToBuffer(_buffer, _data + _last, _encoding, length); if ([_buffer count] > 0) { void *pool = objc_autoreleasePoolPush(); - OFString *characters = transformString(_buffer, 0, true, self); + OFString *characters = transformString(self, _buffer, 0, true); if ([_delegate respondsToSelector: @selector(parser:foundCharacters:)]) [_delegate parser: self foundCharacters: characters]; @@ -511,11 +518,11 @@ else if (_level == 1 && _data[_i] == '>') { void *pool = objc_autoreleasePoolPush(); OFString *PI; appendToBuffer(_buffer, _data + _last, _encoding, _i - _last); - PI = transformString(_buffer, 1, false, nil); + PI = transformString(self, _buffer, 1, false); if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] || [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] || [PI hasPrefix: @"xml\n"]) if (![self OF_parseXMLProcessingInstructions: PI]) @@ -854,11 +861,11 @@ if ((length = _i - _last) > 0) appendToBuffer(_buffer, _data + _last, _encoding, length); pool = objc_autoreleasePoolPush(); - attributeValue = transformString(_buffer, 0, true, self); + attributeValue = transformString(self, _buffer, 0, true); if (_attributePrefix == nil && [_attributeName isEqual: @"xmlns"]) [[_namespaces lastObject] setObject: attributeValue forKey: @""]; if ([_attributePrefix isEqual: @"xmlns"]) @@ -944,11 +951,11 @@ else if (_data[_i] == '>' && _level >= 2) { void *pool = objc_autoreleasePoolPush(); OFString *CDATA; appendToBuffer(_buffer, _data + _last, _encoding, _i - _last); - CDATA = transformString(_buffer, 2, false, nil); + CDATA = transformString(self, _buffer, 2, false); if ([_delegate respondsToSelector: @selector(parser:foundCDATA:)]) [_delegate parser: self foundCDATA: CDATA]; @@ -994,11 +1001,11 @@ @throw [OFMalformedXMLException exceptionWithParser: self]; pool = objc_autoreleasePoolPush(); appendToBuffer(_buffer, _data + _last, _encoding, _i - _last); - comment = transformString(_buffer, 2, false, nil); + comment = transformString(self, _buffer, 2, false); if ([_delegate respondsToSelector: @selector(parser:foundComment:)]) [_delegate parser: self foundComment: comment];