Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer usage of Buffer.from #88

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.mjs

Large diffs are not rendered by default.

34 changes: 24 additions & 10 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 @@ -329,13 +332,18 @@ async function getChangesFromFile(core, file, client, context, id) {
ref: new URL(file.contentsUrl).searchParams.get('ref'),
});

filePatch = Buffer.from(
// The content is base64 encoded but splited with newlines, so we need to remove them before decoding
contentResult.data.encoding === 'base64'
? contentResult.data.content.replaceAll('\n', '')
: contentResult.data.content,
contentResult.data.encoding,
).toString();
if (
typeof contentResult.content === 'string' &&
typeof contentResult.encoding === 'string'
) {
filePatch = Buffer.from(
// The content is base64 encoded but splited with newlines, so we need to remove them before decoding
contentResult.data.encoding === 'base64'
? contentResult.data.content.replaceAll('\n', '')
: contentResult.data.content,
contentResult.data.encoding,
).toString();
}
}

const sourceChanges = [
Expand Down Expand Up @@ -503,7 +511,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 @@ -512,7 +522,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 @@ -521,7 +533,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
Loading