Ticket #1262 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

loadURL does not escape + (plus) character in URL

Reported by: rdewit Owned by:
Priority: minor Milestone: 2.6 Release
Component: examples Version: 2.5
Keywords: Cc:
State: Complete

Description

Not sure if it really is a bug, but the javascript function escape() that is called to URL encode the URL that will be passed to Ajax.Request does not escape the plus character. Some GET requests have a parameter like: ...&format=application/kml+xml&...

These requests will fail and (in my case) get an error back from the server.

Something like this will help it (Ajax.js, line 63):

uri = OpenLayers.ProxyHost + escape(uri.replace(/\+/, "%2B"));

Is that the way to go?

Btw: can we add 'Ajax' to the list of components?

Attachments

proxy.cgi.diff Download (0.7 KB) - added by rdewit 5 years ago.
What about this patch? If the the method is a GET one, replace the + in the url to be a %2B.
ajax.patch Download (0.5 KB) - added by crschmidt 5 years ago.
ajax.2.patch Download (0.9 KB) - added by pspencer 5 years ago.

Change History

Changed 5 years ago by euzuro

  • component changed from general to Ajax

'Ajax' added as new component. Good one, rdewit. :-)

Changed 5 years ago by crschmidt

I don't think this is a bug. "+" is allowed to be in URLs. Can you give an example URL which fails with a '+' in it? If you're using proxy.cgi, it's possible that proxy.cgi is broken.

Changed 5 years ago by crschmidt

  • state changed from Needs Discussion to Awaiting User Feedback

Changed 5 years ago by rdewit

  • state changed from Awaiting User Feedback to Needs Discussion

2 URLs. This first one has a + in it (in Format=application/kml+xml). The other one is exactly the same, but with another format.

 URL with a +

 same URL without a +

Changed 5 years ago by crschmidt

I get the same content from both of these in firefox and curl. Can you explain what the problem is, exactly? (Why does "+" need to be escaped when it's not here?)

Changed 5 years ago by crschmidt

Talked on IRC: This is a misbehavior in proxy.cgi, not OpenLayers.Ajax, we think. Proxy.cgi parses the string, turns the "+" into a " ", then re-encodes it as "%20" When talking to the server.

Escaping the "+" will 'fix' the problem, but that's a workaround for a bug, I believe.

Changed 5 years ago by rdewit

  • state changed from Needs Discussion to Needs More Work
  • component changed from Ajax to examples

Changed 5 years ago by rdewit

What about this patch? If the the method is a GET one, replace the + in the url to be a %2B.

Changed 5 years ago by rdewit

  • state changed from Needs More Work to Needs Discussion

Changed 5 years ago by tschaub

The problem is the use of escape (in JavaScript). We should never use escape and should always use either encodeURI or encodeURIComponent (depending on what is being encoded).

 http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Predefined_Functions:escape_and_unescape_Functions

Changed 5 years ago by crschmidt

Tim:

Neither escape nor encodeURI escape the "+" character that is causing rdewit problems. Although I'm willing to accept that we're using the wrong thing, can you explain to me what part of that solves this problem?

Changed 5 years ago by crschmidt

  • state changed from Needs Discussion to Needs More Work

encodeURIComponent should be called on the part we put in url.

Changed 5 years ago by crschmidt

This change should be in Ol.LoadURL, btw.

Changed 5 years ago by crschmidt

Changed 5 years ago by crschmidt

  • state changed from Needs More Work to Review

Changed 5 years ago by pspencer

  • state changed from Review to Commit

Works for me!

Changed 5 years ago by crschmidt

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [5865]) loadURL does not escape + (plus) character in proxied URL. Thanks to rdewit for following up on this, and to tschaub for reminding us of the right way to do things. r=pagameba (Closes #1262)

Changed 5 years ago by tschaub

  • status changed from closed to reopened
  • resolution fixed deleted

Works? The spelling is encodeURIComponent.

Changed 5 years ago by pspencer

/me goes back to testing school ... I wonder where the patch did apply? Honestly, I did apply it and test it but now I look at what I ran and I don't see the patched code ...

Changed 5 years ago by crschmidt

  • status changed from reopened to closed
  • resolution set to fixed

Well, it's now got *real* tests, which I've just run in Opera, Safari, and Firefox, and committed as r5866 (under the "It's a stupid typo" rule), so I think this is okay now. Thanks for the catch, Tim, and sorry for the poor testing.

Changed 5 years ago by pspencer

Changed 5 years ago by pspencer

opps. I was hoping to fix it first since I didn't catch it the first time through. please ignore patch.

Note: See TracTickets for help on using tickets.