Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

events created with newline in the description are lost #7

Open
ceich opened this issue Feb 23, 2018 · 5 comments
Open

events created with newline in the description are lost #7

ceich opened this issue Feb 23, 2018 · 5 comments

Comments

@ceich
Copy link

ceich commented Feb 23, 2018

The new event UI has a textarea for the description, which invites use of newlines. The Save button seems to work: the app goes from NewEvent back to Home and the new event appears briefly, but it then disappears.

I see a complaint in the console about an unescaped control character (decimal 10 is newline):

Uncaught (in promise) Error: GraphQL error: Unable to parse the JSON document: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
 at [Source: (String)"{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "three
four" }
    }
}"; line: 11, column: 38]
 at [Source: (String)"{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "three
four" }
    }
}"; line: 11, column: 38]
@ceich
Copy link
Author

ceich commented Feb 23, 2018

When I edit an event in DynamoDB console to have a newline in the description, it properly shows as \n in the console, but the app displays it as a space.

@ceich
Copy link
Author

ceich commented Feb 23, 2018

A simple fix would be to escape() before creating and unescape() before displaying, but the job of satisfying DynamoDB's need for valid JSON seems to belong to the GraphQL layer or the Resolver.

@mikeparisstuff
Copy link
Contributor

Ah, I see what you mean. This is a limitation of the request mapping template currently as the result of the evaluated template is expected to be a JSON object that will be used to configure the call to DynamoDB. You can currently pass mutli-line strings through to dynamodb by referencing an argument on the context.

For example if you had this:

{
    "version": "2017-02-28",
    "operation": "PutItem",
    "key": {
        "id": { "S": "5f7a4c6d-eee0-474a-b4ca-2b52e953a8bf"}
    },
    "attributeValues": {
        "name": { "S": "one" },
        "where": { "S": "two" },
        "when": { "S": "2018-02-23T00:15:00Z" },
        "description": { "S": "$ctx.args.description" }
    }
}

You can pass a description with newlines as you might expect. I'll take a note of this and look into the possibility of escaping the evaluated template. Thanks for the feedback!

@Zerquix18
Copy link

@mikeparisstuff this solution does not work for me. I'm using RDS and it only fails when the description has a new line

@Zerquix18
Copy link

So what fixed the issue in my case was to escape the value with:

$util.escapeJavaScript()

eg:

"$util.escapeJavaScript($ctx.args.long_description)"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants