noriah / ashe

Library for accessing the Riot API from Node.js - NO LONGER MAINTAINED
Other
2 stars 0 forks source link

Proper URL encoding #4

Open TiFu opened 7 years ago

TiFu commented 7 years ago

Hey,

I found an issue with character encoding in urls. E. g. https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/Scârry?api_key= returns 400 Bad Request, but is valid from the dev portal. This is because request does not encode the url properly. There is an open pull request (https://github.com/request/request/issues/1678) for the request package since May 10.

As a workaround the following code can be inserted before https://github.com/noriah/ashe/blob/master/lib/worker.js#L150

      var urlLib = require("url");
      var parsedUrl = urlLib.parse(url)
      // Encode path if needed
      let parts = urlLib.parse(parsedUrl)
      if (parts.pathname && parts.host !== 'unix') {
        // Prevent double encoding
        parts.pathname = encodeURI(decodeURI(parts.pathname))
        parsedUrl = urlLib.format(parts)
      }
      url = urlLib.parse(parsedUrl)

Do you want to implement it or should I create a PR?

iFonny commented 7 years ago

pull request pls