After plenty of searching and stepping into the implementation for curl-transport.js, I have found a way to work around this issue. It relies on understanding of what curl-transport passes to require('child_process').exec
.
Essentially the mechanism works by starting a new process for CURL and passing in command line arguments. By having round brackets, it confuses CURL and by having spaces it confuses the command line argument parsing. So to work around it, simply add a double quote as the first character of the username and an ending double quote as the last character of the password; so when the two strings get concatenated (ie: username+":"+password) then the final string will be "USERNAME:PASSWORD"
which get's passed as one argument to the process.
My node code looks like this:
var bitbucket = require('bitbucket-api');
var credentials = { username: '"USERNAME', password: 'PASSWORD With Spaces and ()s"' };
var client = bitbucket.createClient(credentials);
var repository = client.getRepository({ slug: 'repoName', owner: 'USERNAME' }, function (err, repo) {
//Code to access the repo object.
console.log(repo);
});
Notice how username has an additional double quote at the beginning of the value (this is the hack). I have added spaces and emphasised it below because it's not obvious::
Notice how password has an additional double quote at the end of the value (this is the hack). I have added spaces and emphasised it below because it's not obvious:
- password: 'PASSWORD With Spaces and ()s " '
The call will then succeed and you will get back the details for your repository.
BTW, this fix worked for me in V0.0.6 of bitbucket-api on Windows 8.
A helpful note:
On windows, please remember to put the following into your path so that it can find CURL. You can do this through [Win8: Windows-X]->System->Advanced System Settings->Advanced->System Variables->Path->Edit...
Make sure git's binaries are in the path for CURL:
C:\Program Files (x86)\Git\bin
Also, if you are trying to get it to work on heroku then you might need to work around pathing issues by re-installing the Heroku toolbelt under C:\Heroku (see other posts for why) and adding the following to the path:
C:\Heroku\ruby-1.9.2\bin;C:\Heroku\bin;C:\Program Files (x86)\Git\bin