Author |
|
patrickm Senior Member
Joined: February 22 2007 Location: United States
Online Status: Offline Posts: 188
|
Posted: June 25 2012 at 23:18 | IP Logged
|
|
|
Does anybody know of any PH functions that would do URL encoding?
ph_htmlescape() does some characters but not all possible/typical ASCII characters.
Patrick
|
Back to Top |
|
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: June 28 2012 at 07:40 | IP Logged
|
|
|
This is a good question. I did some testing and ph_htmlescape does not seem to do anything with ascii control
characters such as CR/LF and TAB, which are valid characters in a URL when they are properly encoded. (%0d,
%0a, and %09).
Perhaps the misconception here is that ph_htmlescape is just that--an HTML escaper, not a URL escaper. Dave, I
think we really need a function for URL encoding. Right now I have to pipe everything I want to send to a web
server through something like this:
ph_htmlescape(ph_replaceall(ph_replaceall("{TEST}",CHAR(13), "%0d"),CHAR(10),"%0a"))
And that doesn't even take care of TAB characters or the also valid BACKSPACE character (why anyone would want
to send a backspace is beyond me, but nonetheless...)
__________________ Skip
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: June 28 2012 at 14:24 | IP Logged
|
|
|
Hmmm...I checked the sourcecode and you're correct. Im not escaping CR/LF, tab, or BS characters. I also checked all instances where Im using this function internally and Im only using this to properly escape URL's. I don't use it anywhere to escape HTML sequences so I guess I originally intended for this function to be a URL escaper.
The characters that are currently escaped are:
%#<> "'&=?@:;/+
I can modify the current function to handle the extra characters. I don't think I need to add BS because there is no way that I know of to embed an actual BS character within a string so that I can even escape it. Of course you can include an already escaped backspace character within a string but I cant check for the existence of an unescaped BS character. Or I can add a new function with the additional characters escaped in case modifying the existing function would cause a problem for existing code. The new function could also include an additional parameter that would "control" what escape characters to search for. I'd probably need to do some research to see what characters need to be escaped for both URL's and general HTML to see how this extra parameter should be utilized.
In any event, I'll get the changes done in the next beta (which will hopefully be very soon with the I2CS changes) since its an easy mod.
Dave.
|
Back to Top |
|
|
MrGibbage Super User
Joined: October 23 2006 Location: United States
Online Status: Offline Posts: 513
|
Posted: June 28 2012 at 15:11 | IP Logged
|
|
|
Dave, you are a Rock Star! Thanks!
I don't think I would ever miss BS, so do whatever you want with it.
__________________ Skip
|
Back to Top |
|
|