Thanks again, DrAzzy and Gordon. I've got one step closer.
OAuth URI encoding seem to have some extra ok characters. And it wants to see upper case letters after %. With this modified encodeURIComponent function, Espruino passed testEncode(). Yeah!
function encodeURIComponent(s) {
var ok = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~";
var r = "";
for (var i=0;i<s.length;i++) {
if (ok.indexOf(s[i])>=0) r+=s[i];
else r+= "%"+(256+s.charCodeAt(i)).toString(16).toUpperCase().substr(-2);
}
return r;
}
The next hurdle is regular expression in parseUri function.
parseUri: function parseUri (str) {
/* This function was adapted from parseUri 1.2.1
http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js
*/
var o = {key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
parser: {strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/ }};
var m = o.parser.strict.exec(str);
var uri = {};
var i = 14;
while (i--) uri[o.key[i]] = m[i] || "";
return uri;
}
Well, Espruino already has url.parse function so I think I could use it with some key re-mapping. I'm going to try...
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Thanks again, DrAzzy and Gordon. I've got one step closer.
OAuth URI encoding seem to have some extra ok characters. And it wants to see upper case letters after %. With this modified encodeURIComponent function, Espruino passed testEncode(). Yeah!
The next hurdle is regular expression in parseUri function.
Well, Espruino already has url.parse function so I think I could use it with some key re-mapping. I'm going to try...