You are reading a single comment by @aerialist_user6911 and its replies. Click here to read the full conversation.
  • 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...

About