Skip to content

Commit e7c299b

Browse files
Patrick McElhaneyPatrick McElhaney
authored andcommitted
fix(commit): allow quotes in commit message
Fixes an issue in which quotes in the description were not escaped and would cause cz to fail.
1 parent c514f56 commit e7c299b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/git/commit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ function commit(sh, repoPath, message, options, done) {
1313

1414
var alreadyEnded = false;
1515
let dedentedMessage = dedent(message);
16+
let escapedMessage = dedentedMessage.replace(/"/g, '\\"');
1617
let operatingSystemNormalizedMessage;
1718
// On windows we must use an array in gulp-git instead of a string because
1819
// command line parsing works differently
1920
if(os.platform()=="win32") {
20-
operatingSystemNormalizedMessage = dedentedMessage.split(/\r?\n/);
21+
operatingSystemNormalizedMessage = escapedMessage.split(/\r?\n/);
2122
} else {
22-
operatingSystemNormalizedMessage = dedentedMessage;
23+
operatingSystemNormalizedMessage = escapedMessage;
2324
}
2425

2526
// Get a gulp stream based off the config

test/tests/commit.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,51 @@ describe('commit', function() {
7474

7575
});
7676

77+
it('should commit message with quotes', function(done) {
78+
79+
this.timeout(config.maxTimeout); // this could take a while
80+
81+
// SETUP
82+
83+
let dummyCommitMessage = `sip sip sippin' on some "sizzurp"`;
84+
85+
// Describe a repo and some files to add and commit
86+
let repoConfig = {
87+
path: config.paths.endUserRepo,
88+
files: {
89+
dummyfile: {
90+
contents: `duck-duck-goose`,
91+
filename: `mydummyfile.txt`,
92+
},
93+
gitignore: {
94+
contents: `node_modules/`,
95+
filename: `.gitignore`
96+
}
97+
}
98+
};
99+
100+
// Describe an adapter
101+
let adapterConfig = {
102+
path: path.join(repoConfig.path, '/node_modules/cz-jira-smart-commit'),
103+
npmName: 'cz-jira-smart-commit'
104+
};
105+
106+
// Quick setup the repos, adapter, and grab a simple prompter
107+
let prompter = quickPrompterSetup(sh, repoConfig, adapterConfig, dummyCommitMessage);
108+
// TEST
109+
110+
// Pass in inquirer but it never gets used since we've mocked out a different
111+
// version of prompter.
112+
commitizenCommit(sh, inquirer, repoConfig.path, prompter, {disableAppendPaths:true, quiet:true, emitData:true}, function() {
113+
log(repoConfig.path, function(logOutput) {
114+
expect(logOutput).to.have.string(dummyCommitMessage);
115+
done();
116+
});
117+
});
118+
119+
});
120+
121+
77122
it('should commit multiline messages', function(done) {
78123

79124
this.timeout(config.maxTimeout); // this could take a while

0 commit comments

Comments
 (0)