Skip to content

Instantly share code, notes, and snippets.

@mschoch
Created July 3, 2011 19:20
Show Gist options
  • Save mschoch/1062516 to your computer and use it in GitHub Desktop.
Save mschoch/1062516 to your computer and use it in GitHub Desktop.
Double percent-encoding of document identifiers
//
// 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