summaryrefslogtreecommitdiffstats
path: root/WebKit/mac/Misc/WebNSURLExtras.mm
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/mac/Misc/WebNSURLExtras.mm')
-rw-r--r--WebKit/mac/Misc/WebNSURLExtras.mm61
1 files changed, 45 insertions, 16 deletions
diff --git a/WebKit/mac/Misc/WebNSURLExtras.mm b/WebKit/mac/Misc/WebNSURLExtras.mm
index d956f09..2affbed 100644
--- a/WebKit/mac/Misc/WebNSURLExtras.mm
+++ b/WebKit/mac/Misc/WebNSURLExtras.mm
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2007, 2008, 2009 Apple Inc. All rights reserved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
*
* Redistribution and use in source and binary forms, with or without
@@ -619,21 +619,9 @@ static CFStringRef createStringWithEscapedUnsafeCharacters(CFStringRef string)
return result;
}
-typedef struct {
- NSString *scheme;
- NSString *user;
- NSString *password;
- NSString *host;
- CFIndex port; // kCFNotFound means ignore/omit
- NSString *path;
- NSString *query;
- NSString *fragment;
-} WebKitURLComponents;
-
-- (NSURL *)_webkit_URLByRemovingComponent:(CFURLComponentType)component
+- (NSURL *)_web_URLByTruncatingOneCharacterBeforeComponent:(CFURLComponentType)component
{
CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)self, component, NULL);
- // Check to see if a fragment exists before decomposing the URL.
if (fragRg.location == kCFNotFound)
return self;
@@ -656,12 +644,53 @@ typedef struct {
- (NSURL *)_webkit_URLByRemovingFragment
{
- return [self _webkit_URLByRemovingComponent:kCFURLComponentFragment];
+ return [self _web_URLByTruncatingOneCharacterBeforeComponent:kCFURLComponentFragment];
}
- (NSURL *)_webkit_URLByRemovingResourceSpecifier
{
- return [self _webkit_URLByRemovingComponent:kCFURLComponentResourceSpecifier];
+ return [self _web_URLByTruncatingOneCharacterBeforeComponent:kCFURLComponentResourceSpecifier];
+}
+
+- (NSURL *)_web_URLByRemovingComponentAndSubsequentCharacter:(CFURLComponentType)component
+{
+ CFRange range = CFURLGetByteRangeForComponent((CFURLRef)self, component, 0);
+ if (range.location == kCFNotFound)
+ return self;
+
+ // Remove one subsequent character.
+ ++range.length;
+
+ UInt8* urlBytes;
+ UInt8 buffer[2048];
+ CFIndex numBytes = CFURLGetBytes((CFURLRef)self, buffer, 2048);
+ if (numBytes == -1) {
+ numBytes = CFURLGetBytes((CFURLRef)self, NULL, 0);
+ urlBytes = static_cast<UInt8*>(malloc(numBytes));
+ CFURLGetBytes((CFURLRef)self, urlBytes, numBytes);
+ } else
+ urlBytes = buffer;
+
+ if (numBytes < range.location)
+ return self;
+ if (numBytes < range.location + range.length)
+ range.length = numBytes - range.location;
+
+ memmove(urlBytes + range.location, urlBytes + range.location + range.length, numBytes - range.location + range.length);
+
+ NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingUTF8, NULL));
+ if (!result)
+ result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, numBytes - range.length, kCFStringEncodingISOLatin1, NULL));
+
+ if (urlBytes != buffer)
+ free(urlBytes);
+
+ return result ? [result autorelease] : self;
+}
+
+- (NSURL *)_web_URLByRemovingUserInfo
+{
+ return [self _web_URLByRemovingComponentAndSubsequentCharacter:kCFURLComponentUserInfo];
}
- (BOOL)_webkit_isJavaScriptURL