• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Conversion Between path URLs with certain percent escapes not being removed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Conversion Between path URLs with certain percent escapes not being removed


  • Subject: Conversion Between path URLs with certain percent escapes not being removed
  • From: "Daniel Brieck Jr." <email@hidden>
  • Date: Fri, 18 Jan 2008 22:01:17 -0500

Hello all,

I am trying to go from a local URL path such as "/Volumes/TV% 20SHOWS/" and convert it to "cifs://MSHOME;DANIELBR@DELLOPTIPLEXGX1/TV SHOWS"

Within that conversion I am using FSPathMakeRef() of Files.h which does not like to see percent encoded strings passed into it. So I try to filter them out and replace them with their character representations.

However, the problem occurs with the percent escape in the local URL path given above, they are not converted as expected.

I am using the function CFURLCreateStringByReplacingPercentEscapes() of CFURL.h to remove the percent escapes. However with this above example it does not appear to be removing the and replacing it with a single SPACE.

Also I have tried the CFURLCreateStringByReplacingPercentEscapesUsingEncoding() , but have only been able to successfully remove %escapes but without replacing the characters represented. See commented out trial below, I have tried all the Built-in String Encodings types with no good results of replacing the " " with a SPACE.

For example this local path "/Volumes/MSHOME;DELLOPTIPLEXGX1/" and its ; a.k.a ";" convert ok and allow the code to run and return a result, but passing in something like this "/Volumes/TV SHOWS/" causes an assertion check to fail since it is passing in a %-- sequence at this point below for the newPath parameter.

	err = FSPathMakeRef( (const UInt8*) newPath, &ref, NULL);
       assert(err == noErr);

It has to be some kind of character encoding interpretation issue, any ideas as to what I may be doing wrong would be greatly appreciated. See the Implementation below for the more complete picture of the conversion process.

Thank you,
Daniel J. Brieck Jr.
Note: that I am running Mac Os x 10.4.11 (Intel) on Xcode 2.5

The implementation file:

@implementation NSApplication (getServerURL)


- (NSString *) urlStringForServerVolume:(const char *) path { OSStatus err; FSRef ref; FSCatalogInfo catInfo; CFURLRef url; CFStringRef str; NSString * result; CFStringRef noPercentsPath; CFStringRef stPath; CFIndex size; char* newPath = NULL;

//Testing
       printf("Given path\n");
       printf("%s\n", path);
       printf("end given path\n");

       //Check that the supplied path is not NULL
       assert(path != NULL);

//Converts the const char * to a CFStringRef
stPath = CFStringCreateWithCString (kCFAllocatorDefault, path, kCFStringEncodingUTF8);
assert(stPath != NULL);


//Checking for any percent escape sequences and replacing them with their character equivalents
noPercentsPath = CFURLCreateStringByReplacingPercentEscapes (kCFAllocatorDefault , stPath, CFSTR(" ") );


//noPercentsPath = CFURLCreateStringByReplacingPercentEscapesUsingEncoding (kCFAllocatorDefault , stPath, CFSTR(" "), kCFStringEncodingUnicode );


// Converting from CFStringRef to a UTF8 character encoding
//size = CFStringGetMaximumSizeForEncoding(CFStringGetLength (noPercentsPath), kCFStringEncodingUTF8) + 1;
size = CFStringGetMaximumSizeOfFileSystemRepresentation (noPercentsPath);


newPath = malloc(size);
if (newPath != NULL)
{
printf("This Works\n");
Boolean testVal = CFStringGetCString (noPercentsPath, newPath, size, kCFStringEncodingUTF8);
//Boolean testVal = CFStringGetCString (noPercentsPath, newPath, size, kCFStringEncodingUTF16);
assert(testVal == 1);
}


//Testing
       printf("Print Path\n");
       printf("%s\n",newPath);
       printf("END IT\n");

       err = FSPathMakeRef( (const UInt8*) newPath, &ref, NULL);
       assert(err == noErr);



err = FSGetCatalogInfo(&ref, kFSCatInfoVolume, &catInfo, NULL, NULL, NULL);
assert(err == noErr);
err = FSCopyURLForVolume(catInfo.volume, &url);
assert(err == noErr);
str = CFURLGetString(url);
assert(str != NULL);
result = [NSString stringWithString:(NSString *) str];
assert(result != nil);



//Free some stuff

       free(newPath); newPath = NULL;
       CFRelease(url);
       CFRelease(noPercentsPath);

       return result;
}

@end



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Conversion Between path URLs with certain percent escapes not being removed
      • From: Steve Christensen <email@hidden>
  • Prev by Date: Re: Starting an alert sheet from an NSWindowController that owns a user-editable sheet
  • Next by Date: "Convert to Objective-c 2.0"
  • Previous by thread: Re: Determining MIME types
  • Next by thread: Re: Conversion Between path URLs with certain percent escapes not being removed
  • Index(es):
    • Date
    • Thread