ObjFW  Check-in [6e5a920567]

Overview
Comment:Add OFUnknownXMLEntityException

Additionally, OFXMLParser now uses OFMalformedXMLException instead of
OFInvalidFormatException on invalid entities.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6e5a9205672417ed931a6e69b0a08f32fa7c5032554e5eb74f460472dc57b654
User & Date: js on 2014-07-07 22:05:11
Other Links: manifest | tags
Context
2014-07-07
22:28
OFURL: Allow all RFC 1808 compatible schemes check-in: 65afbedbd4 user: js tags: trunk
22:05
Add OFUnknownXMLEntityException check-in: 6e5a920567 user: js tags: trunk
00:50
OFURL: Don't include the leading "/" in path check-in: d2487bc7e1 user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [499822eb9c] to [c6a5f00302].

347
348
349
350
351
352
353


354
355
356
357
358
359
360
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362







+
+







		4B90B7A1133AD87D00BD33CB /* OFAddressTranslationFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B797133AD87D00BD33CB /* OFAddressTranslationFailedException.m */; };
		4B90B7A2133AD87D00BD33CB /* OFBindFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B798133AD87D00BD33CB /* OFBindFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B90B7A3133AD87D00BD33CB /* OFBindFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B799133AD87D00BD33CB /* OFBindFailedException.m */; };
		4B90B7A4133AD87D00BD33CB /* OFConnectionFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79A133AD87D00BD33CB /* OFConnectionFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B90B7A5133AD87D00BD33CB /* OFConnectionFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */; };
		4B90B7A6133AD87D00BD33CB /* OFListenFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B90B7A7133AD87D00BD33CB /* OFListenFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */; };
		4B91FD12196B4F5900C5C25E /* OFUnknownXMLEntityException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B91FD10196B4F5900C5C25E /* OFUnknownXMLEntityException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B91FD13196B4F5900C5C25E /* OFUnknownXMLEntityException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B91FD11196B4F5900C5C25E /* OFUnknownXMLEntityException.m */; };
		4B9361A81511000C00DCD16B /* OFThreadPool.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B9361A61511000C00DCD16B /* OFThreadPool.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B9361A91511000C00DCD16B /* OFThreadPool.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B9361A71511000C00DCD16B /* OFThreadPool.m */; };
		4B989C2F13771A3700109A30 /* OFSerialization.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B989C2E13771A3700109A30 /* OFSerialization.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B9BB7BD141CDE2D000AD1CC /* OFArray_adjacentSubarray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B9BB7B9141CDE2D000AD1CC /* OFArray_adjacentSubarray.h */; };
		4B9BB7BE141CDE2D000AD1CC /* OFArray_adjacentSubarray.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B9BB7BA141CDE2D000AD1CC /* OFArray_adjacentSubarray.m */; };
		4B9BB7BF141CDE2D000AD1CC /* OFArray_subarray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B9BB7BB141CDE2D000AD1CC /* OFArray_subarray.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B9BB7C0141CDE2D000AD1CC /* OFArray_subarray.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B9BB7BC141CDE2D000AD1CC /* OFArray_subarray.m */; };
811
812
813
814
815
816
817


818
819
820
821
822
823
824
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828







+
+







		4B90B797133AD87D00BD33CB /* OFAddressTranslationFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFAddressTranslationFailedException.m; path = src/exceptions/OFAddressTranslationFailedException.m; sourceTree = "<group>"; };
		4B90B798133AD87D00BD33CB /* OFBindFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFBindFailedException.h; path = src/exceptions/OFBindFailedException.h; sourceTree = "<group>"; };
		4B90B799133AD87D00BD33CB /* OFBindFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFBindFailedException.m; path = src/exceptions/OFBindFailedException.m; sourceTree = "<group>"; };
		4B90B79A133AD87D00BD33CB /* OFConnectionFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFConnectionFailedException.h; path = src/exceptions/OFConnectionFailedException.h; sourceTree = "<group>"; };
		4B90B79B133AD87D00BD33CB /* OFConnectionFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFConnectionFailedException.m; path = src/exceptions/OFConnectionFailedException.m; sourceTree = "<group>"; };
		4B90B79C133AD87D00BD33CB /* OFListenFailedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFListenFailedException.h; path = src/exceptions/OFListenFailedException.h; sourceTree = "<group>"; };
		4B90B79D133AD87D00BD33CB /* OFListenFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFListenFailedException.m; path = src/exceptions/OFListenFailedException.m; sourceTree = "<group>"; };
		4B91FD10196B4F5900C5C25E /* OFUnknownXMLEntityException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFUnknownXMLEntityException.h; path = src/exceptions/OFUnknownXMLEntityException.h; sourceTree = "<group>"; };
		4B91FD11196B4F5900C5C25E /* OFUnknownXMLEntityException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFUnknownXMLEntityException.m; path = src/exceptions/OFUnknownXMLEntityException.m; sourceTree = "<group>"; };
		4B9361A61511000C00DCD16B /* OFThreadPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFThreadPool.h; path = src/OFThreadPool.h; sourceTree = "<group>"; };
		4B9361A71511000C00DCD16B /* OFThreadPool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFThreadPool.m; path = src/OFThreadPool.m; sourceTree = "<group>"; };
		4B981CDE116F71DD00294DB7 /* OFSeekableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSeekableStream.h; path = src/OFSeekableStream.h; sourceTree = "<group>"; };
		4B981CDF116F71DD00294DB7 /* OFSeekableStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSeekableStream.m; path = src/OFSeekableStream.m; sourceTree = "<group>"; };
		4B989C2E13771A3700109A30 /* OFSerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSerialization.h; path = src/OFSerialization.h; sourceTree = "<group>"; };
		4B99250F12E0780000215DBE /* OFHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFHTTPRequest.h; path = src/OFHTTPRequest.h; sourceTree = "<group>"; };
		4B99251012E0780000215DBE /* OFHTTPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFHTTPRequest.m; path = src/OFHTTPRequest.m; sourceTree = "<group>"; };
1067
1068
1069
1070
1071
1072
1073


1074
1075
1076
1077
1078
1079
1080
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086







+
+







				4B55A0FE133ABEA900B58A93 /* OFThreadStillRunningException.m */,
				4B17FFA7133A34DF003E6DCD /* OFTruncatedDataException.h */,
				4B17FFA8133A34E1003E6DCD /* OFTruncatedDataException.m */,
				4B17FFB3133A374C003E6DCD /* OFUnboundNamespaceException.h */,
				4B17FFB4133A3750003E6DCD /* OFUnboundNamespaceException.m */,
				4BD77FDC176E4BC40031C497 /* OFUnboundPrefixException.h */,
				4BD77FDD176E4BC40031C497 /* OFUnboundPrefixException.m */,
				4B91FD10196B4F5900C5C25E /* OFUnknownXMLEntityException.h */,
				4B91FD11196B4F5900C5C25E /* OFUnknownXMLEntityException.m */,
				4B6743EF163C384A00EB1E59 /* OFUnlockFailedException.h */,
				4B6743F0163C384A00EB1E59 /* OFUnlockFailedException.m */,
				4B17FFAF133A3658003E6DCD /* OFUnsupportedProtocolException.h */,
				4B17FFB0133A365C003E6DCD /* OFUnsupportedProtocolException.m */,
				4BA4846015CC9F1E00D75360 /* OFUnsupportedVersionException.h */,
				4BA4846115CC9F1E00D75360 /* OFUnsupportedVersionException.m */,
				4B55A110133AC24500B58A93 /* OFWriteFailedException.h */,
1673
1674
1675
1676
1677
1678
1679

1680
1681
1682
1683
1684
1685
1686
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693







+







				4B6743F3163C384A00EB1E59 /* OFStillLockedException.h in Headers */,
				4B17FFA9133A34E7003E6DCD /* OFTruncatedDataException.h in Headers */,
				4B55A0FF133ABEA900B58A93 /* OFThreadJoinFailedException.h in Headers */,
				4B55A101133ABEA900B58A93 /* OFThreadStartFailedException.h in Headers */,
				4B55A103133ABEA900B58A93 /* OFThreadStillRunningException.h in Headers */,
				4B17FFB5133A375B003E6DCD /* OFUnboundNamespaceException.h in Headers */,
				4BD77FDE176E4BC40031C497 /* OFUnboundPrefixException.h in Headers */,
				4B91FD12196B4F5900C5C25E /* OFUnknownXMLEntityException.h in Headers */,
				4B6743F5163C384A00EB1E59 /* OFUnlockFailedException.h in Headers */,
				4B17FFB1133A3664003E6DCD /* OFUnsupportedProtocolException.h in Headers */,
				4BA4846215CC9F1E00D75360 /* OFUnsupportedVersionException.h in Headers */,
				4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */,
				4B55A109133AC05100B58A93 /* common.h in Headers */,
				4B2B3E7D140D430500EC2F7C /* OFArray_adjacent.h in Headers */,
				4B9BB7BD141CDE2D000AD1CC /* OFArray_adjacentSubarray.h in Headers */,
2051
2052
2053
2054
2055
2056
2057

2058
2059
2060
2061
2062
2063
2064
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072







+







				4B6743F4163C384A00EB1E59 /* OFStillLockedException.m in Sources */,
				4B55A100133ABEA900B58A93 /* OFThreadJoinFailedException.m in Sources */,
				4B55A102133ABEA900B58A93 /* OFThreadStartFailedException.m in Sources */,
				4B55A104133ABEA900B58A93 /* OFThreadStillRunningException.m in Sources */,
				4B17FFAA133A34E7003E6DCD /* OFTruncatedDataException.m in Sources */,
				4B17FFB6133A375B003E6DCD /* OFUnboundNamespaceException.m in Sources */,
				4BD77FDF176E4BC40031C497 /* OFUnboundPrefixException.m in Sources */,
				4B91FD13196B4F5900C5C25E /* OFUnknownXMLEntityException.m in Sources */,
				4B6743F6163C384A00EB1E59 /* OFUnlockFailedException.m in Sources */,
				4B17FFB2133A3664003E6DCD /* OFUnsupportedProtocolException.m in Sources */,
				4BA4846315CC9F1E00D75360 /* OFUnsupportedVersionException.m in Sources */,
				4B55A117133AC24600B58A93 /* OFWriteFailedException.m in Sources */,
				4B5C112F17E9AB3E003C917F /* forwarding.S in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;

Modified src/OFString+XMLUnescaping.m from [966d2aeae2] to [8b7d306c79].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+







#include "config.h"

#include <string.h>

#import "OFString.h"

#import "OFInvalidFormatException.h"
#import "OFUnknownXMLEntityException.h"

int _OFString_XMLUnescaping_reference;

static OF_INLINE OFString*
parseNumericEntity(const char *entity, size_t length)
{
	of_unichar_t c;
149
150
151
152
153
154
155
156
157


158
159
160
161
162
163
164
150
151
152
153
154
155
156


157
158
159
160
161
162
163
164
165







-
-
+
+








				name = [OFString
				    stringWithUTF8String: entity
						  length: entityLength];
				tmp = lookup(context, self, name);

				if (tmp == nil)
					@throw [OFInvalidFormatException
					    exception];
					@throw [OFUnknownXMLEntityException
					    exceptionWithEntityName: name];

				[ret appendString: tmp];
				objc_autoreleasePoolPop(pool);
			}

			last = i + 1;
			inEntity = false;

Modified src/OFXMLParser.m from [006e6e5905] to [7ca3cc1d6a].

29
30
31
32
33
34
35

36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43







+







#import "OFStream.h"
#ifdef OF_HAVE_FILES
# 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];
static state_function_t lookupTable[OF_XMLPARSER_NUM_STATES];

55
56
57
58
59
60
61
62
63


64
65
66
67
68
69
70
56
57
58
59
60
61
62


63
64
65
66
67
68
69
70
71







-
-
+
+







		[buffer addItems: [tmp UTF8String]
			   count: [tmp UTF8StringLength]];
		objc_autoreleasePoolPop(pool);
	}
}

static OFString*
transformString(OFDataArray *buffer, size_t cut, bool unescape,
    id <OFStringXMLUnescapingDelegate> delegate)
transformString(OFXMLParser *parser, OFDataArray *buffer, size_t cut,
    bool unescape)
{
	char *items;
	size_t i, length;
	bool hasEntities = false;
	OFString *ret;

	items = [buffer items];
83
84
85
86
87
88
89
90
91








92
93
94
95
96
97
98
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105







-
-
+
+
+
+
+
+
+
+







		} else if (items[i] == '&')
			hasEntities = true;
	}

	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*
namespaceForPrefix(OFString *prefix, OFArray *namespaces)
{
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368







-
+







		return;

	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];

		objc_autoreleasePoolPop(pool);
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







	if (_data[_i] == '?')
		_level = 1;
	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])
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873







-
+







	if (_data[_i] != _delimiter)
		return;

	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"])
		[[_namespaces lastObject] setObject: attributeValue
					     forKey: _attributeName];
942
943
944
945
946
947
948
949

950
951
952
953
954
955
956
949
950
951
952
953
954
955

956
957
958
959
960
961
962
963







-
+







	if (_data[_i] == ']')
		_level++;
	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];

		objc_autoreleasePoolPop(pool);
992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004
1005
1006
999
1000
1001
1002
1003
1004
1005

1006
1007
1008
1009
1010
1011
1012
1013







-
+








	if (_data[_i] != '>')
		@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];

	objc_autoreleasePoolPop(pool);

Modified src/exceptions/Makefile from [7d7ccc279a] to [1eae683fe5].

34
35
36
37
38
39
40

41
42
43
44
45
46
47
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+







       OFRemoveItemFailedException.m			\
       OFSeekFailedException.m				\
       OFSetOptionFailedException.m			\
       OFStillLockedException.m				\
       OFTruncatedDataException.m			\
       OFUnboundNamespaceException.m			\
       OFUnboundPrefixException.m			\
       OFUnknownXMLEntityException.m			\
       OFUnlockFailedException.m			\
       OFUnsupportedProtocolException.m			\
       OFUnsupportedVersionException.m			\
       OFWriteFailedException.m				\
       ${USE_SRCS_SOCKETS}				\
       ${USE_SRCS_THREADS}
SRCS_SOCKETS = OFAcceptFailedException.m		\

Added src/exceptions/OFUnknownXMLEntityException.h version [230a07c7f0].


























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

/*!
 * @class OFUnknownXMLEntityException \
 *	  OFUnknownXMLEntityException.h ObjFW/OFUnknownXMLEntityException.h
 *
 * @brief An exception indicating that a parser encountered an unknown XML
 *	  entity.
 */
@interface OFUnknownXMLEntityException: OFException
{
	OFString *_entityName;
}

#ifdef OF_HAVE_PROPERTIES
@property (readonly, copy) OFString *entityName;
#endif

/*!
 * @brief Creates a new, autoreleased unknown XML entity exception.
 *
 * @param entityName The name of the unknown XML entity
 * @return A new, autoreleased unknown XML entity exception
 */
+ (instancetype)exceptionWithEntityName: (OFString*)entityName;

/*!
 * @brief Initializes an already allocated unknown XML entity exception.
 *
 * @param entityName The name of the unknown XML entity
 * @return An initialized unknown XML entity exception
 */
- initWithEntityName: (OFString*)entityName;

/*!
 * @brief Returns the name of the unknown XML entity
 *
 * @return The name of the unknown XML entity
 */
- (OFString*)entityName;
@end

Added src/exceptions/OFUnknownXMLEntityException.m version [b1e91714f8].































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "OFUnknownXMLEntityException.h"
#import "OFString.h"

#import "common.h"

@implementation OFUnknownXMLEntityException
+ (instancetype)exceptionWithEntityName: (OFString*)entityName
{
	return [[[self alloc] initWithEntityName: entityName] autorelease];
}

- initWithEntityName: (OFString*)entityName
{
	self = [super init];

	@try {
		_entityName = [entityName copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_entityName release];

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"A parser encountered an unknown XML entity named %@!",
	    _entityName];
}

- (OFString*)entityName
{
	OF_GETTER(_entityName, true)
}
@end

Modified tests/OFStringTests.m from [52259e231b] to [08a115e708].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40







+







#import "OFURL.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFUnknownXMLEntityException.h"

#import "macros.h"

#import "TestsAppDelegate.h"

static OFString *module = @"OFString";
static OFString* whitespace[] = {
661
662
663
664
665
666
667
668
669


670
671

672
673

674
675

676
677

678
679

680
681
682
683
684
685
686
662
663
664
665
666
667
668


669
670
671

672
673

674
675

676
677

678
679

680
681
682
683
684
685
686
687







-
-
+
+

-
+

-
+

-
+

-
+

-
+







	TEST(@"-[stringByXMLUnescaping]",
	    [[s[0] stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&
	    [[@"&#x79;" stringByXMLUnescaping] isEqual: @"y"] &&
	    [[@"&#xe4;" stringByXMLUnescaping] isEqual: @"ä"] &&
	    [[@"&#8364;" stringByXMLUnescaping] isEqual: @"€"] &&
	    [[@"&#x1D11E;" stringByXMLUnescaping] isEqual: @"𝄞"])

	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#1", OFInvalidFormatException, [@"&foo;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect unknown entities in -[stringByXMLUnescaping]",
	    OFUnknownXMLEntityException, [@"&foo;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#2", OFInvalidFormatException, [@"x&amp" stringByXMLUnescaping])
	    @"#1", OFInvalidFormatException, [@"x&amp" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#3", OFInvalidFormatException, [@"&#;" stringByXMLUnescaping])
	    @"#2", OFInvalidFormatException, [@"&#;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#4", OFInvalidFormatException, [@"&#x;" stringByXMLUnescaping])
	    @"#3", OFInvalidFormatException, [@"&#x;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#5", OFInvalidFormatException, [@"&#g;" stringByXMLUnescaping])
	    @"#4", OFInvalidFormatException, [@"&#g;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#6", OFInvalidFormatException, [@"&#xg;" stringByXMLUnescaping])
	    @"#5", OFInvalidFormatException, [@"&#xg;" stringByXMLUnescaping])

	TEST(@"-[stringByXMLUnescapingWithDelegate:]",
	    (h = [[[EntityHandler alloc] init] autorelease]) &&
	    [[@"x&foo;y" stringByXMLUnescapingWithDelegate: h]
	    isEqual: @"xbary"])

#ifdef OF_HAVE_BLOCKS