Skip to content

Commit

Permalink
Sanitise user input
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan committed Jan 20, 2021
1 parent 611823b commit a5f45f5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/reset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const exec = require('async-execute');
*/
module.exports = async function(destination, { hard = true } = {}) {
if (destination && typeof destination === 'string') {
return await exec(`git reset ${destination} ${hard ? '--hard' : ''}`);
return await exec(`git reset ${JSON.stringify(destination)} ${hard ? '--hard' : ''}`);
}

if (destination && typeof destination === 'number') {
Expand Down
4 changes: 2 additions & 2 deletions lib/reset/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('lib/reset', async() => {

it('Should hard reset to a given sha', async() => {
reset('shaid');
expect(exec.getCall(0).args[0]).to.equal('git reset shaid --hard');
expect(exec.getCall(0).args[0]).to.equal('git reset "shaid" --hard');
});

it('Should hard reset to n commits back', async() => {
Expand All @@ -47,6 +47,6 @@ describe('lib/reset', async() => {

it('Should reset w/o hard argument', async() => {
reset('shaid', { hard: false });
expect(exec.getCall(0).args[0].trim()).to.equal('git reset shaid');
expect(exec.getCall(0).args[0].trim()).to.equal('git reset "shaid"');
});
});
4 changes: 2 additions & 2 deletions lib/tag/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ module.exports = async function(tag) {
exec(`git config user.name "${await author}"`),
exec(`git config user.email "${await email}"`),
]);
await exec(`git tag -a ${tag} -m "${await message}"`);
await exec(`git push origin refs/tags/${tag}`);
await exec(`git tag -a ${JSON.stringify(tag)} -m "${await message}"`);
await exec(`git push origin ${JSON.stringify(`refs/tags/${tag}`)}`);
};
4 changes: 2 additions & 2 deletions lib/tag/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('lib/tag', async() => {
dummy.stub = command => lines.push(command);

await gitTag('1.1.1');
expect(lines).to.include('git tag -a 1.1.1 -m "this is a message"');
expect(lines).to.include('git push origin refs/tags/1.1.1');
expect(lines).to.include('git tag -a "1.1.1" -m "this is a message"');
expect(lines).to.include('git push origin "refs/tags/1.1.1"');
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "async-git",
"version": "1.13.0",
"version": "1.13.1",
"description": "👾 Retrieve data from current git repository",
"keywords": [
"git",
Expand Down

0 comments on commit a5f45f5

Please sign in to comment.