NetTalk Central

Author Topic: Function for Percent Encoding?  (Read 3707 times)

debzidoodle

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
    • Email
Function for Percent Encoding?
« on: April 29, 2014, 04:57:05 AM »
Hi Bruce,

Is there a function that will perform Percent Encoding?  The p_web.EncodeWebString is a little to agressive, percent encoding is like the PHP function rawurlencode https://php.net/manual/en/function.rawurlencode.php

Thanks
Debra

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Function for Percent Encoding?
« Reply #1 on: April 30, 2014, 01:57:23 AM »
Hi Debra,

>> The p_web.EncodeWebString is a little too aggressive...

You need to qualify this a bit. This method does "percent encoding" but it does take a "flags" parameter which can alter the behavior a bit. Flags is a "bitwise" parameter, meaning you can add these equates together.

For example, setting flags to Net:Dos means the following characters are not encoded
/ \ . $

If flags  includes net:NoHex or net:NoPlus then spaces are left along.
If flags contains net:BigPlus then spaces are encoded to %20.
Otherwise spaces are encoded as +

if flags contains net:NoColon then colons are not encoded.

All letters (A-Z and a-z) and numbers (0-9) are not encoded.

Everything not mentioned above, is encoded.

Sorry to answer your question more completely, I need to know what you find "too aggressive" about it.  :)

Cheers
Bruce




debzidoodle

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
    • Email
Re: Function for Percent Encoding?
« Reply #2 on: April 30, 2014, 04:40:30 AM »
The flags is what I was missing...  I overlooked that somehow   :)  

It almost gets me where I need to be with the net:dos, except I need the / encoded.  Or you could look at it another way, I need to keep the . with a non-flag encode.

I am doing oAuth, and I have to make the strings encoded in my signature.  So here is an example of a string as it has to be encoded for the signature to be valid
This is my string
Code: [Select]
oauth_callback='http://10.211.55.4:88/qbGetOAuthAccessToken'I need it to look like this
Code: [Select]
oauth_callback_Encoded = 'http%3A%2F%2F10.211.55.4%3A88%2FqbGetOAuthAccessToken'
p_web.encodeWebstring(oauth_callback,net:dos) gives me 'http%3A//10.211.55.4%3A88/qbGetOAuthAccessToken'

and

p_web.encodeWebstring(oauth_callback) gives me 'http%3A%2F%2F10%2E211%2E55%2E4%3A88%2FqbGetOAuthAccessToken'

Edit:
Here is a description of what I need:
Quote
Returns a string in which all non-alphanumeric characters except -_.~ have been replaced with a percent (%) sign followed by two hex digits. This is the encoding described in ยป RFC 3986 for protecting literal characters from being interpreted as special URL delimiters, and for protecting URLs from being mangled by transmission media with character conversions (like some email systems).
I found this here: http://stackoverflow.com/questions/996139/urlencode-vs-rawurlencode
Thank you!

Debra
« Last Edit: April 30, 2014, 06:42:06 AM by debzidoodle »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Function for Percent Encoding?
« Reply #3 on: April 30, 2014, 09:50:02 PM »
Hi Debra,

I've added a flag net:php for the next build which preserves that combination. I suspect you'll want to use it in combination with net:BigPlus

Cheers
Bruce
« Last Edit: May 02, 2014, 05:19:53 AM by Bruce »

debzidoodle

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
    • Email
Re: Function for Percent Encoding?
« Reply #4 on: May 01, 2014, 12:19:09 PM »
Thank you!!!