mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
add support for data:,xxx style URL
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35568 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7302652db0
commit
adc4c8d5e6
3 changed files with 111 additions and 84 deletions
|
@ -1,3 +1,9 @@
|
|||
2012-09-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSURL.m:
|
||||
* Tests/base/NSURL/basic.m:
|
||||
Add support for data: URL
|
||||
|
||||
2012-09-10 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSJSONSerialization.m:
|
||||
|
|
183
Source/NSURL.m
183
Source/NSURL.m
|
@ -1608,44 +1608,48 @@ static NSUInteger urlAlign;
|
|||
- (NSString*) _pathWithEscapes: (BOOL)withEscapes
|
||||
{
|
||||
NSString *path = nil;
|
||||
unsigned int len = 3;
|
||||
|
||||
if (_baseURL != nil)
|
||||
if (YES == myData->isGeneric || 0 == myData->scheme)
|
||||
{
|
||||
if (baseData->path && *baseData->path)
|
||||
unsigned int len = 3;
|
||||
|
||||
if (_baseURL != nil)
|
||||
{
|
||||
len += strlen(baseData->path);
|
||||
}
|
||||
else if (baseData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if (myData->path && *myData->path)
|
||||
{
|
||||
len += strlen(myData->path);
|
||||
}
|
||||
else if (myData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
if (len > 3)
|
||||
{
|
||||
char buf[len];
|
||||
char *ptr;
|
||||
char *tmp;
|
||||
if (baseData->path && *baseData->path)
|
||||
{
|
||||
len += strlen(baseData->path);
|
||||
}
|
||||
else if (baseData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if (myData->path && *myData->path)
|
||||
{
|
||||
len += strlen(myData->path);
|
||||
}
|
||||
else if (myData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
if (len > 3)
|
||||
{
|
||||
char buf[len];
|
||||
char *ptr;
|
||||
char *tmp;
|
||||
|
||||
ptr = [self _path: buf withEscapes: withEscapes];
|
||||
ptr = [self _path: buf withEscapes: withEscapes];
|
||||
|
||||
/* Remove any trailing '/' from the path for MacOS-X compatibility.
|
||||
*/
|
||||
tmp = ptr + strlen(ptr) - 1;
|
||||
if (tmp > ptr && *tmp == '/')
|
||||
{
|
||||
*tmp = '\0';
|
||||
}
|
||||
/* Remove any trailing '/' from the path for MacOS-X compatibility.
|
||||
*/
|
||||
tmp = ptr + strlen(ptr) - 1;
|
||||
if (tmp > ptr && *tmp == '/')
|
||||
{
|
||||
*tmp = '\0';
|
||||
}
|
||||
|
||||
path = [NSString stringWithUTF8String: ptr];
|
||||
path = [NSString stringWithUTF8String: ptr];
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
@ -1751,40 +1755,47 @@ static NSUInteger urlAlign;
|
|||
|
||||
- (NSString*) resourceSpecifier
|
||||
{
|
||||
NSRange range = [_urlString rangeOfString: @"://"];
|
||||
|
||||
if (range.length > 0)
|
||||
if (YES == myData->isGeneric)
|
||||
{
|
||||
NSString *specifier;
|
||||
NSRange range = [_urlString rangeOfString: @"://"];
|
||||
|
||||
/* MacOSX compatibility - in the case where there is no
|
||||
* host in the URL, just return the path (without the "//").
|
||||
* For all other cases we return the whole specifier.
|
||||
*/
|
||||
if (nil == [self host])
|
||||
{
|
||||
specifier = [_urlString substringFromIndex: NSMaxRange(range)];
|
||||
}
|
||||
if (range.length > 0)
|
||||
{
|
||||
NSString *specifier;
|
||||
|
||||
/* MacOSX compatibility - in the case where there is no
|
||||
* host in the URL, just return the path (without the "//").
|
||||
* For all other cases we return the whole specifier.
|
||||
*/
|
||||
if (nil == [self host])
|
||||
{
|
||||
specifier = [_urlString substringFromIndex: NSMaxRange(range)];
|
||||
}
|
||||
else
|
||||
{
|
||||
specifier = [_urlString substringFromIndex: range.location+1];
|
||||
}
|
||||
return specifier;
|
||||
}
|
||||
else
|
||||
{
|
||||
specifier = [_urlString substringFromIndex: range.location+1];
|
||||
}
|
||||
return specifier;
|
||||
{
|
||||
/*
|
||||
* Cope with URLs missing net_path info - <scheme>:/<path>...
|
||||
*/
|
||||
range = [_urlString rangeOfString: @":"];
|
||||
if (range.length > 0)
|
||||
{
|
||||
return [_urlString substringFromIndex: range.location + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _urlString;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Cope with URLs missing net_path info - <scheme>:/<path>...
|
||||
*/
|
||||
range = [_urlString rangeOfString: @":"];
|
||||
if (range.length > 0)
|
||||
{
|
||||
return [_urlString substringFromIndex: range.location + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _urlString;
|
||||
}
|
||||
return [NSString stringWithUTF8String: myData->path];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2025,34 +2036,38 @@ static NSUInteger urlAlign;
|
|||
- (NSString*) fullPath
|
||||
{
|
||||
NSString *path = nil;
|
||||
unsigned int len = 3;
|
||||
|
||||
if (_baseURL != nil)
|
||||
if (YES == myData->isGeneric || 0 == myData->scheme)
|
||||
{
|
||||
if (baseData->path && *baseData->path)
|
||||
unsigned int len = 3;
|
||||
|
||||
if (_baseURL != nil)
|
||||
{
|
||||
len += strlen(baseData->path);
|
||||
}
|
||||
else if (baseData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if (myData->path && *myData->path)
|
||||
{
|
||||
len += strlen(myData->path);
|
||||
}
|
||||
else if (myData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
if (len > 3)
|
||||
{
|
||||
char buf[len];
|
||||
char *ptr;
|
||||
if (baseData->path && *baseData->path)
|
||||
{
|
||||
len += strlen(baseData->path);
|
||||
}
|
||||
else if (baseData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if (myData->path && *myData->path)
|
||||
{
|
||||
len += strlen(myData->path);
|
||||
}
|
||||
else if (myData->hasNoPath == NO)
|
||||
{
|
||||
len++;
|
||||
}
|
||||
if (len > 3)
|
||||
{
|
||||
char buf[len];
|
||||
char *ptr;
|
||||
|
||||
ptr = [self _path: buf withEscapes: NO];
|
||||
path = [NSString stringWithUTF8String: ptr];
|
||||
ptr = [self _path: buf withEscapes: NO];
|
||||
path = [NSString stringWithUTF8String: ptr];
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -296,6 +296,12 @@ GSPathHandling("right");
|
|||
PASS([url resourceDataUsingCache: NO] != nil,
|
||||
"can load file URL with anchor");
|
||||
|
||||
url = [NSURL URLWithString: @"data:,a23"];
|
||||
PASS_EQUAL([url scheme], @"data", "can get scheme of data URL");
|
||||
PASS_EQUAL([url path], nil, "path of data URL is nil");
|
||||
PASS_EQUAL([url host], nil, "host of data URL is nil");
|
||||
PASS_EQUAL([url resourceSpecifier], @",a23", "resourceSpecifier of data URL");
|
||||
PASS_EQUAL([url absoluteString], @"data:,a23", "can get string of data URL");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue