What's wrong with this percentage encoding?


#1

So, I’m writing a custom library in Dart (because there are none yet).

I can successfully auth and send tweets on behalf of the user, as long as it does not contain character such as: ¤ ! ( ´ ) ä £

So a tweet message like this works: testingthise±}{[]$@

So it seems some characters cause issues. I’m not sure why. I’m encoding like this:

String encode(String content) {
return content.replaceAllMapped(new RegExp(’[^0-9a-zA-Z-_~.]’), (Match match) {
return ‘%${match.group(0).codeUnits.first.toRadixString(16)}’.toUpperCase();
});
}

Examples:

“testingthise!” -> "testingthise%21"
“testingthise±}{[]$@” -> “testingthise%2B-%7D%7B%5B%5D%24%40”

So the first one with !-char does not authenticate (could not auth you, code 32). But the second one works fine.

Example signature base string:

POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&oauth_consumer_key%3Db9KGHq5S2CVn1CZZ4AfUUg%26oauth_nonce%3D88108%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1367868005%26oauth_token%3D1344216829-t4FLclugOt7h35knDDAVlAnOkMw0YlN0J2MUWwK%26oauth_version%3D1.0%26status%3Dtestingthise%2521

Any ideas why this may not work with some chars?


#2

Jesus… and after hours of debugging, now that I wrote here I managed to get it to work. I have double encoding the params within signature base string.