From f9278d0f476e54cf6e27729018d87f51f5e7370f Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Wed, 3 Jul 2013 20:47:11 -0400 Subject: [PATCH] encoding fix for real --- cgi.d | 15 ++++++++++++++- oauth.d | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cgi.d b/cgi.d index 768c4b9..e8af5c1 100644 --- a/cgi.d +++ b/cgi.d @@ -2147,7 +2147,7 @@ string rawurlencode(in char[] data) { } else { ret ~= '%'; // since we iterate on char, this should give us the octets of the full utf8 string - ret ~= toHex(c); + ret ~= toHexUpper(c); } } @@ -2182,6 +2182,19 @@ string toHex(long num) { return to!string(array(ret.retro)); } +string toHexUpper(long num) { + string ret; + while(num) { + int v = num % 16; + num /= 16; + char d = cast(char) ((v < 10) ? v + '0' : (v-10) + 'A'); + ret ~= d; + } + + return to!string(array(ret.retro)); +} + + // the generic mixins /// Use this instead of writing your own main diff --git a/oauth.d b/oauth.d index 0dbe0c4..68d8815 100644 --- a/oauth.d +++ b/oauth.d @@ -274,14 +274,14 @@ string tweet(OAuthParams params, string oauthToken, string tokenSecret, string m "token_secret" : tokenSecret, ]; - auto data = "status=" ~ rawurlencode(message);//encodeVariables(["status" : message]); + auto data = "status=" ~ rawurlencode(message);//.replace("%3F", "?");//encodeVariables(["status" : message]); auto ret = curlOAuth(params, "http://api.twitter.com" ~ "/1.1/statuses/update.json", args, "POST", data); auto val = jsonToVariant(ret).get!(Variant[string]); if("id_str" !in val) throw new Exception("bad result from twitter: " ~ ret); - return to!string(val);//val["id_str"].get!string; + return val["id_str"].get!string; } import std.file;