View Full Version : Help with URL loading

Jun 29, 2012, 03:06 PM
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:


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


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.

Jun 29, 2012, 03:28 PM
You'll probably need to post the code that uses Webkit.

When I look at the two strings:
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:
A: %22testing%22&signalRConnectionId=123
B: -2.642388e-229sting2signalRConnectionId=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.

Jun 29, 2012, 03:55 PM
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.

Jun 29, 2012, 05:22 PM
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.