From 22ac223817f9a2681cc9955caac0609bda763031 Mon Sep 17 00:00:00 2001 From: Tomas Coufal Date: Wed, 9 Nov 2022 17:43:57 +0100 Subject: [PATCH] fix: Remove carriage return injected by issue edits Signed-off-by: Tomas Coufal --- packages/probot-issue-form/parser.test.ts | 11 +++++++++++ packages/probot-issue-form/parser.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/probot-issue-form/parser.test.ts b/packages/probot-issue-form/parser.test.ts index 1f8012ab..5751334c 100644 --- a/packages/probot-issue-form/parser.test.ts +++ b/packages/probot-issue-form/parser.test.ts @@ -254,6 +254,17 @@ describe('parse', () => { expect(data).toEqual({ thisIsInput: 'value' }); }); + it('single input with carriage return', async () => { + const context = { + payload: { issue: { body: '### This is input field\r\n\r\nvalue' } }, + log: console, + }; + + const data = await parser.parse(context); + + expect(data).toEqual({ thisIsInput: 'value' }); + }); + it('no match', async () => { const context = { payload: { issue: { body: '### Something else\n\nvalue' } }, diff --git a/packages/probot-issue-form/parser.ts b/packages/probot-issue-form/parser.ts index a159acf2..fd0e72fc 100644 --- a/packages/probot-issue-form/parser.ts +++ b/packages/probot-issue-form/parser.ts @@ -223,7 +223,8 @@ export const fetchTemplates = async (context: any): Promise => { export const parse = async ( context: any ): Promise> => { - const body = context.payload.issue.body || ''; + const body = + (context.payload.issue.body as string).replaceAll('\r\n', '\n') || ''; const templates = (await fetchTemplates(context)) .map((f) => ({ file: f,