Skip to content

Commit

Permalink
fix: sanitize type and category in next-release filename (#3692)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Apr 6, 2021
1 parent ead5575 commit 4f79915
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-changelog-release-ae823f1f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "changelog/release",
"description": "Sanitize type and category in next-release filename"
}
11 changes: 10 additions & 1 deletion scripts/changelog/change-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ function generateRandomIdentifier() {
return crypto.randomBytes(4).toString('hex');
}

/**
* Escapes illegal characters from filename
* Ref: https://github.com/aws/aws-sdk-js/issues/3691
*/
function sanitizeFileName(filename) {
return filename.replaceAll(/[^a-zA-Z0-9\\.]/g, '-');
}

var CHANGES_DIR = path.join(process.cwd(), '.changes');

/**
Expand Down Expand Up @@ -169,7 +177,8 @@ ChangeCreator.prototype = {
return config['inFile'];
}
// Determine default location
var newFileName = this._type + '-' + this._category + '-' + generateRandomIdentifier() + '.json';
var newFileName = sanitizeFileName(this._type) + '-' + sanitizeFileName(this._category)
+ '-' + generateRandomIdentifier() + '.json';
return path.join(process.cwd(), '.changes', 'next-release', newFileName);
},

Expand Down

0 comments on commit 4f79915

Please sign in to comment.