Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wbynum

macrumors newbie
Original poster
Jun 29, 2012
13
3
At my work we have an Objective C app that loads a URL into a stripped down web browser. From what I understand the browser was written using the webkit framework. This works well until the URL has URL encoded characters (example: %22). When the URL is loaded the URL encoded parameters are corrupted. Below is what I am seeing.

Code Snippet:

NSURL *myUrl = [NSURL URLWithString:myUrlString];
RequestURL = [NSURLRequest requestWithURL: myUrl cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval: 60.0];

[[webBrowser mainFrame] loadRequest : RequestURL];

Debugging in Xcode shows "RequestURL" to contain the following correct URL parameters:

clickHereState=%22testing%22&signalRConnectionId=123

When the URL is actually loaded, I have a JS popup that displays window.location.href:

clickHereState=-2.642388e-229sting2signalRConnectionId=123

It's like it is interpreting the URL encoded characters before the request is actually made. If I take out the URL encoded characters, then things work fine. Also, if I just hit the URL directly in Safari, things work fine. Any ideas? Thanks.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
You'll probably need to post the code that uses Webkit.


When I look at the two strings:
Code:
A: %22testing%22&signalRConnectionId=123
B: -2.642388e-229sting2signalRConnectionId=123
String B looks somewhat like string A has been used as a format string, but the parameters being expanded don't really exist. I've hilited the "format" parts of string A, and the "expanded" parts of string B:
Code:
A: [COLOR="Red"]%22te[/COLOR]sting[COLOR="Red"]%22&[/COLOR]signalRConnectionId=123
B: [COLOR="Blue"]-2.642388e-229[/COLOR]sting[COLOR="Blue"]2[/COLOR]signalRConnectionId=123
I'm not saying the formats are working. I'm just saying it looks like the code might be using a stringWithFormat:, or an sprintf(), or some other "withFormat" function or method when it shouldn't be.


Another possibility is defective Javascript for the popup. Again, you'd have to post code, or post an actual URL representing the fail-case.
 

wbynum

macrumors newbie
Original poster
Jun 29, 2012
13
3
Thanks for the tips. I was kind of thinking the same thing. Seems like it is using the % as a format flag (like %d in C). I'll try to dive down into the Webkit code. I know nothing about Objective C though. One of those deals at work where something just get's put on your plate. Thanks again.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
It's not exactly printf-like, nor is it exactly stringWithFormat-like. Neither one has a %t specifier, so it's kinda weird that "%22te" appears to be producing a floating-point number in %e format. But it seems like a good guess it's doing some kind of formatting, since I can't think of a simpler way to get a floating-point number inserted like that.

http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html

https://developer.apple.com/library...onceptual/Strings/Articles/FormatStrings.html
https://developer.apple.com/library...eptual/Strings/Articles/formatSpecifiers.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.