From c8a2c653ee602e308a355d099e05d1246266f514 Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Fri, 23 Mar 2018 15:27:30 -0400 Subject: [PATCH] fixes https://github.com/jonschlinkert/parse-git-config/issues/8 --- index.js | 5 +++++ test/fixtures/_gitconfig-branch | 11 +++++++++++ test/test.js | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/fixtures/_gitconfig-branch diff --git a/index.js b/index.js index ea54819..273cfb3 100644 --- a/index.js +++ b/index.js @@ -160,6 +160,11 @@ parse.expandKeys = function(config) { function parseIni(str, options) { const opts = Object.assign({}, options); + + str = str.replace(/\[(\S+) "(.*)"\]/g, function(m, $1, $2) { + return $1 && $2 ? `[${$1} "${$2.split('.').join('\\.')}"]` : m; + }); + const config = ini.parse(str); if (opts.expandKeys === true) { return parse.expandKeys(config); diff --git a/test/fixtures/_gitconfig-branch b/test/fixtures/_gitconfig-branch new file mode 100644 index 0000000..8b0d1c2 --- /dev/null +++ b/test/fixtures/_gitconfig-branch @@ -0,0 +1,11 @@ +[branch "2.0"] + remote = origin + merge = refs/heads/devel + +[branch "devel"] + remote = origin + merge = refs/heads/devel + +[branch "master"] + remote = origin + merge = refs/heads/devel diff --git a/test/test.js b/test/test.js index 61090b0..afa074f 100644 --- a/test/test.js +++ b/test/test.js @@ -45,6 +45,15 @@ describe('parse-git-config', function() { .catch(cb); }); + it('should not expand dots in keys in config', function(cb) { + parse({ path: fixture('_gitconfig-branch'), expandKeys: true }) + .then(config => { + assert.deepEqual(Object.keys(config.branch), ['devel', 'master', '2.0']) + cb(); + }) + .catch(cb); + }); + it('should include other config sources', function(cb) { parse({ path: fixture('_gitconfig'), include: true }, function(err, config) { assert(!err);