ObjFW  Check-in [4db6713bda]

Overview
Comment:OFString+URLEncoding: Change default allowed chars

This is now unreserved + sub-delims from RFC 3986.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4db6713bda983d8955bcbe20879b5e9ff2b0b8ac3939ec53a97d1ddc7e9506c5
User & Date: js on 2017-10-31 21:55:41
Other Links: manifest | tags
Context
2017-10-31
22:06
OFURL: Add -[URLEncoded*] for encoded components check-in: 03e111614e user: js tags: trunk
21:55
OFString+URLEncoding: Change default allowed chars check-in: 4db6713bda user: js tags: trunk
21:39
OFURL: URL-encode according to RFC 3986 check-in: 5f7305c659 user: js tags: trunk
Changes

Modified src/OFDictionary.m from [21f0c3f7c0] to [26c35d80f1].

582
583
584
585
586
587
588
589

590
591

592
593
594
595
596
597
598
	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		if OF_UNLIKELY (first)
			first = false;
		else
			[ret appendString: @"&"];

		[ret appendString: [[key description] stringByURLEncoding]];

		[ret appendString: @"="];
		[ret appendString: [[object description] stringByURLEncoding]];

	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;







|
>

|
>







582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		if OF_UNLIKELY (first)
			first = false;
		else
			[ret appendString: @"&"];

		[ret appendString: [[key description]
		    stringByURLEncodingWithAllowedCharacters: "-._~!$'()*+,;"]];
		[ret appendString: @"="];
		[ret appendString: [[object description]
		    stringByURLEncodingWithAllowedCharacters: "-._~!$'()*+,;"]];
	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;

Modified src/OFString+URLEncoding.m from [9ad96294d0] to [92e75db2c6].

26
27
28
29
30
31
32
33

34
35
36
37
38
39
40

/* Reference for static linking */
int _OFString_URLEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncoding
{
	return [self stringByURLEncodingWithAllowedCharacters: "$-_.!*()"];

}

- (OFString *)stringByURLEncodingWithAllowedCharacters: (const char *)allowed
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = [self UTF8String];
	char *retCString;







|
>







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

/* Reference for static linking */
int _OFString_URLEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncoding
{
	return [self stringByURLEncodingWithAllowedCharacters:
	    "-._~!$&'()*+,;="];
}

- (OFString *)stringByURLEncodingWithAllowedCharacters: (const char *)allowed
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = [self UTF8String];
	char *retCString;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    ([self UTF8StringLength] * 3) + 1];

	for (i = 0; *string != '\0'; string++) {
		unsigned char c = *string;

		/*
		 * '+' is also listed in RFC 1738, however, '+' is sometimes
		 * interpreted as space in HTTP. Therefore always escape it to
		 * make sure it's always interpreted correctly.
		 */
		if (of_ascii_isalnum(c) || strchr(allowed, c) != NULL)
			retCString[i++] = c;
		else {
			unsigned char high, low;

			high = c >> 4;
			low = c & 0x0F;







<
<
<
<
<







50
51
52
53
54
55
56





57
58
59
60
61
62
63
	if ((retCString = malloc(([self UTF8StringLength] * 3) + 1)) == NULL)
		@throw [OFOutOfMemoryException exceptionWithRequestedSize:
		    ([self UTF8StringLength] * 3) + 1];

	for (i = 0; *string != '\0'; string++) {
		unsigned char c = *string;






		if (of_ascii_isalnum(c) || strchr(allowed, c) != NULL)
			retCString[i++] = c;
		else {
			unsigned char high, low;

			high = c >> 4;
			low = c & 0x0F;

Modified tests/OFStringTests.m from [e5125c6f6a] to [56c53e54e1].

779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
	    @"7ded2f9c279e5addf8be854044bca0cece073fce28eec7d9"])

	TEST(@"-[SHA512Hash]", [[C(@"asdfoobar") SHA512Hash] isEqual:
	    @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56412a9247c"
	    @"3579a329e53a5dc74676b106755e3394f9454a2d42273242615d32f80437d61"])

	TEST(@"-[stringByURLEncoding]",
	    [[C(@"foo\"ba'_~$") stringByURLEncoding]
	    isEqual: @"foo%22ba%27_%7E$"])

	TEST(@"-[stringByURLDecoding]",
	    [[C(@"foo%20bar%22+%24") stringByURLDecoding]
	    isEqual: @"foo bar\"+$"])

	TEST(@"-[insertString:atIndex:]",
	    (s[0] = [mutableStringClass stringWithString: @"π„žΓΆΓΆΓΆbÀ€"]) &&







|
|







779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
	    @"7ded2f9c279e5addf8be854044bca0cece073fce28eec7d9"])

	TEST(@"-[SHA512Hash]", [[C(@"asdfoobar") SHA512Hash] isEqual:
	    @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56412a9247c"
	    @"3579a329e53a5dc74676b106755e3394f9454a2d42273242615d32f80437d61"])

	TEST(@"-[stringByURLEncoding]",
	    [[C(@"foo\"ba'_~$]") stringByURLEncoding]
	    isEqual: @"foo%22ba'_~$%5D"])

	TEST(@"-[stringByURLDecoding]",
	    [[C(@"foo%20bar%22+%24") stringByURLDecoding]
	    isEqual: @"foo bar\"+$"])

	TEST(@"-[insertString:atIndex:]",
	    (s[0] = [mutableStringClass stringWithString: @"π„žΓΆΓΆΓΆbÀ€"]) &&