Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 526172 - Node server can not handle git url with an unexpected tr…
…ailing slash
  • Loading branch information
squarti committed Dec 18, 2017
1 parent 2c8929b commit 4b0a0ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
15 changes: 9 additions & 6 deletions modules/orionode/lib/git/config.js
Expand Up @@ -111,6 +111,7 @@ function getConfig(req, res) {
if (err) {
return writeError(400, res, err.message);
}
var needsWrite = false;
var waitFor = Promise.resolve();
if(options && options.configParams.get("orion.single.user")) {
var user = config.user || (config.user = {});
Expand All @@ -124,18 +125,20 @@ function getConfig(req, res) {
});
return Promise.all([fillUserName,fillUserEmail]);
}).then(function(){
gitUtil.verifyConfigRemoteUrl(config);
args.writeConfigFile(configFile, config, function(err) {});
}).catch(function(err){
if(err.message.indexOf("was not found") !== -1){
return Promise.resolve();
}
needsWrite = true;
}).catch(function(){
return Promise.resolve();
});
}
}
return waitFor.then(function(){
configs = [];

needsWrite |= gitUtil.verifyConfigRemoteUrl(config);
if (needsWrite) {
args.writeConfigFile(configFile, config, function() {});
}

getFullPath(config, "");

writeResponse(200, res, null, {
Expand Down
29 changes: 14 additions & 15 deletions modules/orionode/lib/git/util.js
Expand Up @@ -38,28 +38,27 @@ module.exports.decodeURIComponent = function(path) {
* @version 17.0
*/
module.exports.verifyConfigRemoteUrl = function(config) {
var fixed = false;
var remote = config.remote;
if(remote){
Object.keys(remote).forEach(function(key){
if(Array.isArray(remote[key].url)){
remote[key].url = remote[key].url.map(function(each){
return removeTrailingSlash(each);
remote[key].url = remote[key].url.map(function(url){
if (url.endsWith(".git/")) {
fixed |= true;
return url.slice(0 , -1);
}
return url;
});
} else {
remote[key].url = removeTrailingSlash(remote[key].url);
var url = remote[key].url;
if (url.endsWith(".git/")) {
fixed |= true;
url = url.slice(0 , -1);
}
remote[key].url = url;
}
});
}
return fixed;
};
/**
* @name removeTrailingSlash
* @description Helper method to remove trailing slash of url
* @param url to be checked
* @version 17.0
*/
function removeTrailingSlash(url) {
if(url.endsWith("/")){
url = url.slice(0 , -1);
}
return url;
}

0 comments on commit 4b0a0ae

Please sign in to comment.