ObjFW  Check-in [e2f6ad3876]

Overview
Comment:OFURL: Improve -[initFileURLWithPath:]

This now doesn't use -[initWithString:relativeToURL:] anymore and
properly escapes everything.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e2f6ad3876623ac10c357841b3b3bc18de4c52b4e33ca86948a3db0bdbe8290b
User & Date: js on 2017-11-14 22:50:45
Other Links: manifest | tags
Context
2017-11-14
23:19
Improve -[stringByAppendingPathComponent:] check-in: 80ac05eb8f user: js tags: trunk
22:50
OFURL: Improve -[initFileURLWithPath:] check-in: e2f6ad3876 user: js tags: trunk
00:35
Xcode project: Add missing files check-in: 3e1cd5cb9a user: js tags: trunk
Changes

Modified src/OFURL.m from [dfdfaa21fd] to [18e5b35188].

627
628
629
630
631
632
633


634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653



654
655
656
657
658






659
660
661
662
663
664
665

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{


	@try {
		void *pool = objc_autoreleasePoolPush();
# if OF_PATH_DELIMITER != '/' || defined(OF_WINDOWS) || defined(OF_DJGPP)
		OFArray OF_GENERIC(OFString *) *pathComponents =
		    [path pathComponents];
# endif
		OFURL *currentDirectoryURL;

# if OF_PATH_DELIMITER != '/'
		path = [pathComponents componentsJoinedByString: @"/"];
# endif

# if defined(OF_WINDOWS) || defined(OF_DJGPP)
		if ([[pathComponents firstObject] hasSuffix: @":"])
			path = [path stringByPrependingString: @"/"];
# endif

		if (isDirectory && ![path hasSuffix: OF_PATH_DELIMITER_STRING])
			path = [path stringByAppendingString: @"/"];




		currentDirectoryURL =
		    [[OFFileManager defaultManager] currentDirectoryURL];

		self = [self initWithString: path
			      relativeToURL: currentDirectoryURL];







		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}








>
>






<













>
>
>
|
|

|
|
>
>
>
>
>
>







627
628
629
630
631
632
633
634
635
636
637
638
639
640
641

642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
# if OF_PATH_DELIMITER != '/' || defined(OF_WINDOWS) || defined(OF_DJGPP)
		OFArray OF_GENERIC(OFString *) *pathComponents =
		    [path pathComponents];
# endif


# if OF_PATH_DELIMITER != '/'
		path = [pathComponents componentsJoinedByString: @"/"];
# endif

# if defined(OF_WINDOWS) || defined(OF_DJGPP)
		if ([[pathComponents firstObject] hasSuffix: @":"])
			path = [path stringByPrependingString: @"/"];
# endif

		if (isDirectory && ![path hasSuffix: OF_PATH_DELIMITER_STRING])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";

		if (![path hasPrefix: @"/"]) {
			OFString *currentDirectoryPath = [[OFFileManager
			    defaultManager] currentDirectoryPath];

			path = [OFString stringWithFormat:
			    @"%@/%@", currentDirectoryPath, path];
			path = [path stringByStandardizingURLPath];
		}

		_URLEncodedPath = [[path
		    stringByURLEncodingWithAllowedCharacters:
		    [OFCharacterSet URLPathAllowedCharacterSet]] copy];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}