Skip to content

Commit

Permalink
fix: shell special characters escaping
Browse files Browse the repository at this point in the history
ISSUES CLOSED: leoforfree#107
  • Loading branch information
dudekaa committed Dec 10, 2019
1 parent 51cab09 commit 3e3b7c2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions buildCommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ const addFooter = (footer, config) => {
};

const escapeSpecialChars = result => {
// eslint-disable-next-line no-useless-escape
const specialChars = ['`'];

// eslint-disable-next-line no-useless-escape, prettier/prettier
const specialChars = ['`', '"', '\\$', '!'];
let newResult = result;
// eslint-disable-next-line array-callback-return
specialChars.map(item => {
// If user types "feat: `string`", the commit preview should show "feat: `\string\`".
// Don't worry. The git log will be "feat: `string`"
newResult = result.replace(new RegExp(item, 'g'), '\\`');

specialChars.forEach(item => {
// If user types `feat: "string"`, the commit preview should show `feat: \"string\"`.
// Don't worry. The git log will be `feat: "string"`
newResult = newResult.replace(new RegExp(item, 'g'), `\\${item}`);
});

return newResult;
};

Expand Down

0 comments on commit 3e3b7c2

Please sign in to comment.