mIRC Homepage

Percent encoding?

Posted By: Sjoepele

Percent encoding? - 09/09/15 07:43 PM

I was making this script that tweets out certain stuff through twitter's API and it requires me to 'percent encode' a lot of crap

Now, i looked at the following webpage to check out what they mean by that and it appears to me that its just urlencoding. https://dev.twitter.com/oauth/overview/percent-encoding-parameters

The problem is, the script i use to urlencode does something different from what url encoding normally does:
For instance, if i urlencode the string "HMAC-SHA1" using the tool on the following webpage (http://meyerweb.com/eric/tools/dencoder/), the string stays the same.

but when i encode the same string using the script i usally use for urlencoding, it changes it to "HMAC%2DSHA1".

Here's the script, found it on hawkee:
alias urlencode { return $regsubex($$1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16))) }

Can anyone tell me a bit about the difference between these encodings and/or point me towards an existing script that encodes like the tool on the web page?
Posted By: Loki12583

Re: Percent encoding? - 09/09/15 09:07 PM

The page shows a table of what does not need to be encoded, so include those in the regex's character class:

alias urlencode { return $regsubex($$1-,/([^-.~\w])/g,$+(%,$base($asc(\t),10,16))) }

\w handles 0-9A-Za-z_ so just -.~ needed to be added.
Posted By: Sjoepele

Re: Percent encoding? - 09/09/15 09:10 PM

Loki you're amazing <3 That would have never occurred to me. Thanks!
© 2021 mIRC Discussion Forums