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

CreateContentTask evaluation will not remove illegal characters #16542

Closed
giannik opened this issue Aug 8, 2024 · 9 comments
Closed

CreateContentTask evaluation will not remove illegal characters #16542

giannik opened this issue Aug 8, 2024 · 9 comments
Labels
Milestone

Comments

@giannik
Copy link
Contributor

giannik commented Aug 8, 2024

While upgrading to 2.0 i had a workflow with a CreateContentTask activity to create a specific content type with following liquid expression :



{% capture full_name %}
{{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.FirstName.Text}} {{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.LastName.Text}}
{% endcapture %}

{
  "DisplayText":  "{{full_name}}",
  "Owner":"{{Workflow.Input.User.UserId}}",
  "Author": "{{Workflow.Input.User.UserName}}",
 
}

when ContentProperties is evaluated from :

   var contentProperties = await _expressionEvaluator.EvaluateAsync(ContentProperties, workflowContext, _javaScriptEncoder);

the json to be merged is returned like this (with carriage return inside the json) :


{
  "DisplayText":  "
qqqqqqqqfname qqqqqqqqlname
",
}

this results in the following error when merging with content item :

System.Text.Json.JsonReaderException: '0x0D' (CARRIAGE RETURN) is invalid within a JSON string. The string should be correctly escaped.

This was handeled automatically before 2.0 . Is there a way to remove automatically invalid json characters like previous ?

MikeAlhayek added a commit that referenced this issue Aug 8, 2024
@MikeAlhayek
Copy link
Member

I think this is due to the extra trailing comma in your json.

@hishamco
Copy link
Member

hishamco commented Aug 8, 2024

Is it matter?

@MikeAlhayek
Copy link
Member

@giannik can you please try out this PR and see if that fixes your issue? #16543

@MikeAlhayek
Copy link
Member

Is it matter?

trailing command makes the json invalid by default.

@Piedone Piedone added this to the 2.0 milestone Aug 8, 2024
Copy link
Contributor

github-actions bot commented Aug 8, 2024

We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).

This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.

@sebastienros
Copy link
Member

If the liquid is generated from a generic liquid task, then it doesn't know that the properties should be encoded in JSON.

What may happen in 2.0 is that the parser won't be as permissive as before (NewtonSoft.JSON) and will fail when it finds an invalid char.

The solution, which will also work with the previous version is to correctly encode the values using the json filter like so:

  • use | json such that the properties are well-formed for json
  • remove the trailing comma after Author
  • exclude new lines in the capture using -%
{% capture full_name -%}
{{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.FirstName.Text}} {{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.LastName.Text}}
{%- endcapture %}

{
  "DisplayText":  "{{full_name | json}}",
  "Owner":"{{Workflow.Input.User.UserId | json}}",
  "Author": "{{Workflow.Input.User.UserName | json}}"
}

@sebastienros
Copy link
Member

Feel free to re-open if you have more information that would invalidate the explanation

@giannik
Copy link
Contributor Author

giannik commented Aug 8, 2024

@sebastienros @MikeAlhayek
thanks guys.

adding this to remove whitespaces from left and right fixes it :

{%- capture full_name -%}
{{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.FirstName.Text}} {{Workflow.Input.User.Properties.UserProfileSettings.UserProfileSettings.LastName.Text}}
{%- endcapture %}

@sebastienros
Copy link
Member

But you should also add the json filters. Try with a name containing a double quote. It could be a security issue otherwise

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

Successfully merging a pull request may close this issue.

5 participants