From 24a1542468451f1648891e164e7075ad7c35e7fc Mon Sep 17 00:00:00 2001 From: Tobias Bocanegra Date: Sat, 22 Oct 2022 12:52:49 +0200 Subject: [PATCH] fix: trim spaces after comma (#166) --- src/forms-pipe.js | 2 +- test/forms-pipe.test.js | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/forms-pipe.js b/src/forms-pipe.js index f1001aa9..7fe79175 100644 --- a/src/forms-pipe.js +++ b/src/forms-pipe.js @@ -134,7 +134,7 @@ export async function formsPipe(state, request) { const sourceLocation = resourceFetchResponse.headers.get('x-amz-meta-x-source-location'); const referer = request.headers.get('referer') || 'unknown'; - const sheetNames = sheets.split(','); + const sheetNames = sheets.split(',').map((s) => s.trim()); if (!sourceLocation || !sheetNames.includes('incoming')) { return error(log, `Target workbook at ${resourcePath} is not setup to intake data.`, 403, response); diff --git a/test/forms-pipe.test.js b/test/forms-pipe.test.js index 63119c3f..40cba782 100644 --- a/test/forms-pipe.test.js +++ b/test/forms-pipe.test.js @@ -91,7 +91,7 @@ describe('Form POST Requests', () => { new PipelineResponse('', { headers: { 'x-amz-meta-x-source-location': 'foo-bar', - 'x-amz-meta-x-sheet-names': 'helix-default,incoming', + 'x-amz-meta-x-sheet-names': 'helix-default, incoming', }, }), ), @@ -108,16 +108,27 @@ describe('Form POST Requests', () => { it('successful POST Request w/Body and Custom Headers', async () => { const req = new PipelineRequest('https://helix-pipeline.com/', defaultRequest); const state = new PipelineState(defaultState()); - state.s3Loader.reply( - 'helix-content-bus', - 'foobus/live/metadata.json', - new PipelineResponse(JSON.stringify({ - data: [ - { 'url': '/**', 'access-control-allow-origin': '*' }, - { 'url': '/**', 'content-security-policy': "default-src 'self'" }, - ], - })), - ); + state.s3Loader + .reply( + 'helix-content-bus', + 'foobus/live/metadata.json', + new PipelineResponse(JSON.stringify({ + data: [ + { 'url': '/**', 'access-control-allow-origin': '*' }, + { 'url': '/**', 'content-security-policy': "default-src 'self'" }, + ], + })), + ) + .reply( + 'helix-content-bus', + 'foobus/live/somepath/workbook.json', + new PipelineResponse('', { + headers: { + 'x-amz-meta-x-source-location': 'foo-bar', + 'x-amz-meta-x-sheet-names': 'helix-default,incoming', // without comma after space + }, + }), + ); const resp = await formsPipe(state, req); assert.strictEqual(resp.status, 201);