mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-08 19:57:14 +00:00
New: "//site.com/x" style URL support in CPURL and CFURL.
With this feature, CFURL and CPURL can now correctly transform a relative scheme URL starting with a double-slash. For example, + CPURL URLWithString:@"//a.se/a" relativeToURL:@"ftp://b.se/c" would represent an absolute URL of "ftp://a.se/a".
This commit is contained in:
+10
-3
@@ -277,9 +277,17 @@ function resolveURL(aURL)
|
||||
absoluteBaseURL = baseURL.absoluteURL(),
|
||||
baseParts = PARTS(absoluteBaseURL);
|
||||
|
||||
if (parts.scheme || parts.authority)
|
||||
if (!parts.scheme && parts.authorityRoot)
|
||||
{
|
||||
// Handle "//domain.com/" style links which need to take their scheme from the base URL,
|
||||
// but nothing else.
|
||||
resolvedParts = CFURLPartsCreateCopy(parts);
|
||||
resolvedParts.scheme = baseURL.scheme();
|
||||
}
|
||||
else if (parts.scheme || parts.authority)
|
||||
{
|
||||
resolvedParts = parts;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
resolvedParts = { };
|
||||
@@ -302,7 +310,6 @@ function resolveURL(aURL)
|
||||
resolvedParts.path = parts.path;
|
||||
resolvedParts.pathComponents = pathComponents;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var basePathComponents = baseParts.pathComponents,
|
||||
|
||||
@@ -103,6 +103,16 @@ var exampleProtocol = "http",
|
||||
[self assert:[url lastPathComponent] equals:examplePathRelative];
|
||||
}
|
||||
|
||||
- (void)testUrlWithDoubleSlashRelativeToHttpUrl
|
||||
{
|
||||
[self assert:"http://example2.com/b/a.html" equals:[[CPURL URLWithString:@"//example2.com/b/a.html" relativeToURL:[CPURL URLWithString:@"http://www.example.com/test/"]] absoluteString]];
|
||||
}
|
||||
|
||||
- (void)testUrlWithDoubleSlashRelativeToHttpsUrl
|
||||
{
|
||||
[self assert:"https://example2.com/b/a.html" equals:[[CPURL URLWithString:@"//example2.com/b/a.html" relativeToURL:[CPURL URLWithString:@"https://www.example.com/test/"]] absoluteString]];
|
||||
}
|
||||
|
||||
- (void)testDeleteComponent
|
||||
{
|
||||
var url = [CPURL URLWithString:exampleFullPath];
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
- (void)testRelativeURLs
|
||||
{
|
||||
var URLStrings =
|
||||
var URLStrings =
|
||||
{
|
||||
"g:h" : "g:h",
|
||||
"g" : "http://a/b/c/g",
|
||||
@@ -89,4 +89,11 @@
|
||||
[self assert:new CFURL(URLString).absoluteString() equals:URLStrings[URLString]];
|
||||
}
|
||||
|
||||
- (void)testDoubleSlash
|
||||
{
|
||||
[self assert:"//a" equals:new CFURL("//a").absoluteString()];
|
||||
[self assert:"ftp://a" equals:new CFURL("//a", new CFURL("ftp://example.com/b")).absoluteString()];
|
||||
[self assert:"ftp://example.com/a" equals:new CFURL("/a", new CFURL("ftp://example.com/b")).absoluteString()];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user