Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use " in body for scheduling #3069

Closed
BenRomberg opened this issue Jan 8, 2017 · 0 comments · Fixed by #5268
Closed

Cannot use " in body for scheduling #3069

BenRomberg opened this issue Jan 8, 2017 · 0 comments · Fixed by #5268

Comments

@BenRomberg
Copy link

BenRomberg commented Jan 8, 2017

This is a Bug Report

Description

With the following schedule configuration:

      - schedule:
          rate: rate(1 minute)
          enabled: true
          input:
            path: /switch
            httpMethod: POST
            headers:
              Content-Type: application/json
            queryStringParameters: {}
            body: '{ "functionId": "..." }'

I get the following exception:

SyntaxError: Unexpected token f
    at Object.parse (native)
    at /usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/schedule/index.js:123:41
    at Array.forEach (native)
    at /usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/compile/events/schedule/index.js:21:28

The f comes from the functionId in the body. If I remove the f, the error becomes Unexpected token u (from "unctionId").

Looking at the code, the problem is with escaping the input in lib/plugins/aws/deploy/compile/events/schedule/index.js in the variable scheduleTemplate. The quotes in the body get transformed to \" in Input, and then to \\" in scheduleTemplate. Note the missing backslash - only the original backslack gets escaped, not the quotes.

I was able to hack a quick fix together and it works (not suggesting as a fix, just to illustrate that this would fix it). The original scheduleTemplate was renamed to scheduleTemplate2 before:

const scheduleTemplate = scheduleTemplate2.replace(/\\\\"/g, '\\\\\\"');

Additional Data

  • Serverless Framework Version you're using: 1.4.0, also tried with 1.5.0
  • Operating System: Xubuntu 16.10
  • Stack Trace:
  • Provider Error messages:
@pmuens pmuens added the bug label Jan 9, 2017
@horike37 horike37 added this to the 1.31.0 milestone Sep 4, 2018
horike37 added a commit that referenced this issue Sep 4, 2018
…ody-parsing

Fix for #3069 - Failing to handle schedule event body params due to f…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants