mIRC Home    About    Download    Register    News    Help

Print Thread
#254919 09/09/15 07:43 PM
Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
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:
Code:
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?

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
The page shows a table of what does not need to be encoded, so include those in the regex's character class:

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


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

Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Loki you're amazing <3 That would have never occurred to me. Thanks!


Link Copied to Clipboard