From 381116127a2b5c662b4d2a693d22d073ea9f02cf Mon Sep 17 00:00:00 2001 From: Brian Lu Date: Tue, 2 May 2023 00:00:08 -0400 Subject: [PATCH] replace pubkey slice with regex --- src/flatter.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/flatter.js b/src/flatter.js index 1a7020a..e2ec4e0 100644 --- a/src/flatter.js +++ b/src/flatter.js @@ -143,7 +143,19 @@ async function generateDescription(directory) { if (core.getInput('gpg-sign')) { const {stdout} = await exec.getExecOutput('gpg2', ['--armor', '--export', core.getInput('gpg-sign')]); - const publicKey = stdout.split('\n').slice(2, -2).join(''); + /* + * Regex info: + * -{5}BEGIN.*-{5} + * ^ public key BEGIN header + * ([\w\s/+=]*) + * ^ capture the key (capture group 1) + * \s=[\w\s/+=]* + * ^ ignore the key checksum + * -{5}END.*-{5} + * ^ public key END header + */ + const regex = /-{5}BEGIN.*-{5}([\w\s/+=]*)\s=[\w\s/+=]*-{5}END.*-{5}/; + const publicKey = stdout.match(regex)[1].split('\n').join(''); metadata['GPGKey'] = publicKey; }