From 022199e4aede885a376a693b609871bad76f9f4f Mon Sep 17 00:00:00 2001 From: Bill O'Connell <91283923+wdoconnell@users.noreply.github.com> Date: Fri, 3 Mar 2023 10:29:14 -0500 Subject: [PATCH] fix: prevent recursion in task regex (#6639) --- cypress/e2e/shared/tasks.test.ts | 9 +++++++-- src/tasks/containers/TaskPage.tsx | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/shared/tasks.test.ts b/cypress/e2e/shared/tasks.test.ts index 061b70a7bf..dca9e3a70c 100644 --- a/cypress/e2e/shared/tasks.test.ts +++ b/cypress/e2e/shared/tasks.test.ts @@ -132,13 +132,18 @@ describe('Tasks - TSM', () => { cy.focused() - cy.getByTestID('flux-editor').monacoType(`option task = { + cy.getByTestID('flux-editor') + .monacoType( + `option task = { name: "Option Test", every: 24h, offset: 20m } from(bucket: "defbuck") - |> range(start: -2m)`) + |> range(start: -2m)` + ) + // Fix bug with monaco error inserting an extra } here. + .monacoType('{backSpace}') cy.getByTestID('task-form-name') .click() diff --git a/src/tasks/containers/TaskPage.tsx b/src/tasks/containers/TaskPage.tsx index 9f85e3c307..05e6aefd40 100644 --- a/src/tasks/containers/TaskPage.tsx +++ b/src/tasks/containers/TaskPage.tsx @@ -145,7 +145,9 @@ class TaskPage extends PureComponent { // if the script has a pre-defined option task = {} // we want the taskOptions to take precedence over what is provided in the script // currently we delete that part of the script - script = script.replace(new RegExp('option\\s+task\\s+=\\s+{(.|\\s)*}'), '') + + const removeTaskOptionsRegex = /option\s+task\s+=\s+{(\s|\S)*?}/ + script = script.replace(removeTaskOptionsRegex, '') if (!isValidFlux(script)) { this.props.invalidFlux()