Re: NSURL and percent escaping
Philippe Roussel <[email protected]> Fri, 22 Aug 2025 16:34:08 +0200
| Newsgroups | gmane.comp.lib.gnustep.devel |
|---|---|
| Message-ID | <aKh/[email protected]> |
--XbsF/4Z1PnRCuePI Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit And now with the code... Le Fri, Aug 22, 2025 at 03:33:52PM +0200, Philippe Roussel a écrit : > Hi all, > > I'm trying to instanciate NSURL using -initWithScheme:user:password... > method and I'm having trouble when the user needs escaping. I might be > doing something wrong but I don't understand NSURL behaviour... > > Here is a simplified example : > > NSURL *url = [[NSURL alloc] initWithScheme:@"http" > user:@"p.o.roussel%40free.fr" > password:@"password" > host:@"127.0.0.1" > port:nil > fullPath:@"dav.php/calendars/[email protected]/default/" > parameterString:nil > query:nil > fragment:nil]; > > When I log [url absoluteString] I get the following > > http://p.o.roussel%2540free.fr:[email protected]/dav.php/calendars/[email protected]/default/ > > and I don't understand the '%2540' part. If I use the original non > escaped username -initWithScheme return nil; > > Full example attached, built and run against libgnustep-base.so.1.28. > > Any hint ? > > Thanks, > Philippe > -- > Evolution (n): A hypothetical process whereby infinitely improbable events occur with alarming frequency, order arises from chaos, and no one is given credit. > -- De nombreux hommes doivent leur succès à leur première femme et leur seconde femme à leur succès. Jim Backus --XbsF/4Z1PnRCuePI Content-Type: application/vnd.wolfram.mathematica.package Content-Disposition: attachment; filename="SimpleAgenda.m" Content-Transfer-Encoding: quoted-printable #import <Foundation/Foundation.h>=0A=0Aint main(int argc, const char *argv[= ])=0A{=0A CREATE_AUTORELEASE_POOL(arp);=0A=0A NSString *url =3D @"http://= [email protected]:[email protected]/dav.php/calendars/[email protected]= r/default/";=0A NSString *escapedUrl =3D @"http://p.o.roussel%40free.fr:pa= [email protected]/dav.php/calendars/[email protected]/default/";=0A NSStr= ing *user =3D @"[email protected]";=0A NSString *escapedUser =3D [user s= tringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAl= lowedCharacterSet]];=0A NSLog(@"escaped user : %@", escapedUser);=0A // = =3D> OK : p.o.roussel%40free.fr=0A=0A NSURL *fromString =3D [NSURL URLWith= String:url];=0A NSLog(@"fromString : %@", [fromString absoluteString]);=0A= // =3D> OK : nil=0A=0A=0A NSURL *fromEscapedString =3D [NSURL URLWithStr= ing:escapedUrl];=0A NSLog(@"fromEscapedString : %@", [fromEscapedString ab= soluteString]);=0A // =3D> OK : http://p.o.roussel%40free.fr:password@127.= 0.0.1/dav.php/calendars/[email protected]/default/=0A=0A=0A NSURL *fromP= arts =3D [[NSURL alloc] initWithScheme:@"http"=0A user:user=0A = password:@"password"=0A host:@"127.0.0.1"=0A port:[= NSNumber numberWithInt:80]=0A fullPath:@"dav.php/calendars/p.o.rousse= [email protected]/default/"=0A parameterString:nil=0A query:nil=0A = fragment:nil];=0A NSLog(@"fromParts %@", [fromParts absoluteString]);= =0A // =3D> nil, could auto escape user ?=0A=0A NSURL *fromEscapedParts = =3D [[NSURL alloc] initWithScheme:@"http"=0A user:escapedUser=0A = password:@"password"=0A host:@"127.0.0.1"=0A port= :nil=0A fullPath:@"dav.php/calendars/[email protected]/default/"=0A= parameterString:nil=0A query:nil=0A fragment:nil];=0A= NSLog(@"fromEscapedParts %@", [fromEscapedParts absoluteString]);=0A // = =3D> KO : http://p.o.roussel%2540free.fr:[email protected]/dav.php/calenda= rs/[email protected]/default/=0A=0A=0A RELEASE(arp);=0A return 0;=0A}=0A --XbsF/4Z1PnRCuePI--