discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

question regarding [NSString stringByAddingPercentEscapesUsingEncoding:]


From: Sebastian Reitenbach
Subject: question regarding [NSString stringByAddingPercentEscapesUsingEncoding:]
Date: Mon, 14 Apr 2008 13:01:41 +0200

Hi,

I tried to download a csv file from a webserver.I found an example using 
NSURL.
As the documentation says, NSURL needs an
escaped string, so I used 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding, so I wrote 
the test below:
=================Sample Program================================
#include <Foundation/Foundation.h>

int
main(int argc, const char *argv[])
{
  id pool = [[NSAutoreleasePool alloc] init];

  NSString *GKey = 
@"ABQIAAAAvp3__HwvT3VkixIIbsW0axQuKI_6t1bH2P0vCI_Q8jfpn8qdNBQMnneljxh9czilkau_bYSCXteS_A";




  NSString *Address = @"Potsdamer+Platz+Berlin+Germany";
  NSString *URLString = [NSString 
stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv&key=%@";, 
Address, GKey];
  URLString = [URLString 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  NSLog(@"URL: %@", URLString);
  NSURL *url = [NSURL URLWithString:URLString];
  NSLog(@"NSURL *url: %@", url);
  NSString *coordinates = [NSString stringWithContentsOfURL:url];
  NSArray *coordItems = [coordinates componentsSeparatedByString:@","];
  NSLog(@"Latitude: %@ Longitude: %@", [coordItems objectAtIndex:2], 
[coordItems objectAtIndex:3]);
  NSString *GeoCacheURL = [NSString 
stringWithFormat:@"http://www.geocaching.com/seek/nearest.aspx?origin_lat=%@&origin_long=%@";,




[coordItems objectAtIndex:2], [coordItems objectAtIndex:3]];
  NSLog(@"NewURL: %@", GeoCacheURL);
  [pool release];

  return 0;
}
=================Sample Program================================

Why I now ask is, on the developer@ogo mailing list, 
I got told that 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
might not be implemented correctly. 

=================Snippet from other M/L============================
On 14.04.2008, at 07:15, Sebastian Reitenbach wrote:
>> This would be a major bug in GNUstep, which is quite unlikely. As
>> mentioned the whole approach is utterly wrong. It is more likely that
>> stringByAddingPercentEscapesUsingEncoding only encodes a subset and  
>> is
>> not a proper URL fragment encoder.
> The gnustep documentation to the method implementation starts this  
> way:
> /**
> * Constructs a new ASCII string which is a representation of the  
> receiver
> * in which characters are escaped where necessary in order to  
> produce a
> * legal URL.<br />

If you pipe a whole URL through it and it still can be parsed as a  
URL, its obviously wrong. The whole point of escaping is that the  
result is NOT parsed.
=================Snippet from other M/L============================

As I have no possibility to veryfy who is right, on a MAC, I thought I just 
let
you know, and maybe someone can tell me, who is right.


thank you.
Sebastian






reply via email to

[Prev in Thread] Current Thread [Next in Thread]