Skip to content

Commit b174d80

Browse files
authored
fix(main): #65 quotes break commit (#67)
escape quotes from commit string Closes: #65
1 parent 3c1ddce commit b174d80

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export async function main(config: z.infer<typeof Config>) {
205205

206206

207207
let continue_commit = true;
208-
p.note(build_commit_string(commit_state, config, true), 'Commit Preview')
208+
p.note(build_commit_string(commit_state, config, true, false), 'Commit Preview')
209209
if (config.confirm_commit) {
210210
continue_commit = await p.confirm({message: 'Confirm Commit?'}) as boolean;
211211
if (p.isCancel(continue_commit)) process.exit(0)
@@ -218,14 +218,14 @@ export async function main(config: z.infer<typeof Config>) {
218218

219219
try {
220220
const options = config.overrides.shell ? { shell: config.overrides.shell } : {}
221-
const output = execSync(`git commit -m "${build_commit_string(commit_state, config, false)}"`, options).toString().trim();
221+
const output = execSync(`git commit -m "${build_commit_string(commit_state, config, false, true)}"`, options).toString().trim();
222222
if (config.print_commit_output) p.log.info(output)
223223
} catch(err) {
224224
p.log.error('Something went wrong when committing: ' + err)
225225
}
226226
}
227227

228-
function build_commit_string(commit_state: z.infer<typeof CommitState>, config: z.infer<typeof Config>, colorize: boolean = false): string {
228+
function build_commit_string(commit_state: z.infer<typeof CommitState>, config: z.infer<typeof Config>, colorize: boolean = false, escape_quotes: boolean = false): string {
229229
let commit_string = '';
230230
if (commit_state.type) {
231231
commit_string += colorize ? color.blue(commit_state.type) : commit_state.type
@@ -295,6 +295,10 @@ function build_commit_string(commit_state: z.infer<typeof CommitState>, config:
295295
commit_string += colorize ? `\n\n${color.reset(commit_state.closes)} ${color.magenta(commit_state.ticket)}` : `\n\n${commit_state.closes} ${commit_state.ticket}`;
296296
}
297297

298+
if (escape_quotes) {
299+
commit_string = commit_string.replaceAll('"', '\\"')
300+
}
301+
298302
return commit_string;
299303
}
300304

0 commit comments

Comments
 (0)