Skip to content

Commit

Permalink
Trim whitespace around secret references (#304)
Browse files Browse the repository at this point in the history
Fixes
#303
  • Loading branch information
sethvargo authored Oct 25, 2024
1 parent ca38f18 commit e51ee21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ export class Reference {

this.output = sParts[0].trim();

const ref = sParts.slice(1).join(':');
const refParts = ref.split('/');
// Trim each piece and remove empty entries
const refParts =
sParts
?.slice(1)
?.at(0)
?.split('/')
?.map((p) => (p || '').trim())
?.filter((p) => p !== '') || [];

switch (refParts.length) {
// projects/<p>/locations/<l>/secrets/<s>/versions/<v>
case 8: {
Expand Down
8 changes: 8 additions & 0 deletions tests/reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ test('Reference', { concurrency: true }, async (suite) => {
input: 'out:my-project/my-secret',
expected: 'projects/my-project/secrets/my-secret/versions/latest',
},
{
input: 'out: my-project/my-secret',
expected: 'projects/my-project/secrets/my-secret/versions/latest',
},
{
input: 'out : projects/ my-project/ secrets/ my-secret',
expected: 'projects/my-project/secrets/my-secret/versions/latest',
},
{
input: '',
error: 'TypeError',
Expand Down

0 comments on commit e51ee21

Please sign in to comment.