Created
July 3, 2011 19:20
-
-
Save mschoch/1062516 to your computer and use it in GitHub Desktop.
Double percent-encoding of document identifiers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// TestPercentEscaping | |
// | |
// Created by Marty Schoch on 7/3/11. | |
// Copyright 2011 Hexedit Reality, LLC. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
int main (int argc, const char * argv[]) | |
{ | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
// insert code here... | |
NSURL *root = [NSURL URLWithString:@"http://mschoch.iriscouch.com/notrealdb"]; | |
NSLog(@"Root URL is %@", root); | |
NSString *documentIdentifier = @"document space"; | |
NSLog(@"Document identifier containg space is %@", documentIdentifier); | |
NSString *encodedIdentifier = [(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)documentIdentifier, NULL, CFSTR("/"), kCFStringEncodingUTF8) autorelease]; | |
NSLog(@"Encoded identifier is %@", encodedIdentifier); | |
NSURL *rootWithEncodedIdentifierAppended = [root URLByAppendingPathComponent:encodedIdentifier]; | |
NSLog(@"Wrong: %@", rootWithEncodedIdentifierAppended); | |
NSURL *rootWithIdentifierAppended = [root URLByAppendingPathComponent:documentIdentifier]; | |
NSLog(@"Right: %@", rootWithIdentifierAppended); | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment