Skip to content

Commit

Permalink
Better base64 detection
Browse files Browse the repository at this point in the history
  • Loading branch information
edunad committed Sep 18, 2023
1 parent 312f5ea commit 7457d3e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,18 @@ async function run() {
core.setFailed(`Failed to upload images`);
});

const validateBase64 = function (encoded1) {
var decoded1 = Buffer.from(encoded1, 'base64').toString('utf8');
var encoded2 = Buffer.from(decoded1, 'binary').toString('base64');
return encoded1 == encoded2;
};

const promises = urls.map(
(urlData) =>
new Promise((resolve, reject) => {
const cleanFile = parse(urlData.file).name;
const base64Matcher = new RegExp('/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/');

if (!base64Matcher.test(cleanFile)) {
if (!validateBase64(cleanFile)) {
return resolve({ imageUrl: urlData.url });
} else {
const base64Decode = Buffer.from(cleanFile, 'base64').toString('ascii');
Expand Down

0 comments on commit 7457d3e

Please sign in to comment.