Skip to content

Commit

Permalink
Safer usage of Buffer.from
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Dec 22, 2024
1 parent 413d2e0 commit 9f869f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/index.mjs

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const OUTPUT_NEW_VERSION_NAME = 'new-version';
// Helper functions
function decode(data, encoding) {
if (encoding === BASE64) {
if (typeof data !== 'string') {
return '';
}
const dataBuffer = Buffer.from(data, BASE64);
return dataBuffer.toString(UTF8);
} else {
Expand Down Expand Up @@ -326,10 +329,15 @@ async function getChangesFromFile(core, file, client, context, id) {
ref: file.sha,
});

filePatch = Buffer.from(
contentResult.content,
contentResult.encoding,
).toString();
if (
typeof contentResult.content === 'string' &&
typeof contentResult.encoding === 'string'
) {
filePatch = Buffer.from(
contentResult.content,
contentResult.encoding,
).toString();
}
}

const sourceChanges = [
Expand Down Expand Up @@ -497,7 +505,9 @@ function createReleaseNotes(newVersion, newIcons, updatedIcons, removedIcons) {

let releaseNotes = '';
if (newIcons.length > 0) {
releaseNotes += `\n## ${newIcons.length} new ${newIcons.length > 1 ? 'icons' : 'icon'}\n\n`;
releaseNotes += `\n## ${newIcons.length} new ${
newIcons.length > 1 ? 'icons' : 'icon'
}\n\n`;
for (let newIcon of newIcons.sort(sortAlphabetically)) {
const prs = prNumbersToString(newIcon.prNumbers);
const authors = authorsToString(newIcon.authors);
Expand All @@ -506,7 +516,9 @@ function createReleaseNotes(newVersion, newIcons, updatedIcons, removedIcons) {
}

if (updatedIcons.length > 0) {
releaseNotes += `\n## ${updatedIcons.length} updated ${updatedIcons.length > 1 ? 'icons' : 'icon'}\n\n`;
releaseNotes += `\n## ${updatedIcons.length} updated ${
updatedIcons.length > 1 ? 'icons' : 'icon'
}\n\n`;
for (let updatedIcon of updatedIcons.sort(sortAlphabetically)) {
const prs = prNumbersToString(updatedIcon.prNumbers);
const authors = authorsToString(updatedIcon.authors);
Expand All @@ -515,7 +527,9 @@ function createReleaseNotes(newVersion, newIcons, updatedIcons, removedIcons) {
}

if (removedIcons.length > 0) {
releaseNotes += `\n## ${removedIcons.length} removed ${removedIcons.length > 1 ? 'icons' : 'icon'}\n\n`;
releaseNotes += `\n## ${removedIcons.length} removed ${
removedIcons.length > 1 ? 'icons' : 'icon'
}\n\n`;
for (let removedIcon of removedIcons.sort(sortAlphabetically)) {
const prs = prNumbersToString(removedIcon.prNumbers);
const authors = authorsToString(removedIcon.authors);
Expand Down

0 comments on commit 9f869f6

Please sign in to comment.