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

[Adaptive Cards Templating] AdaptiveCardTemplate not able to parse template string containing \\\" #6153

Closed
pankajvaher opened this issue Aug 2, 2021 · 1 comment · Fixed by #6197

Comments

@pankajvaher
Copy link

pankajvaher commented Aug 2, 2021

Target Platform

Please list the platform(s) that your application is targeting and remove platforms you are not targeting:

  • .NET Templating

Target Application

Teams

Problem Description

new AdaptiveCardTemplate(templateJsonString) is not parsing template json string properly. Hence, we see issues with \” in the template ("$when":"${sysupdatedby != \"\"}").

To work around this problem, we replaced the \” in the template with single quotes.

Note: This issue is NOT observed with JS templating sdk.

Template string

"{\"type\":\"AdaptiveCard\",\"version\":\"1.2\",\"body\":[{\"type\":\"ColumnSet\",\"columns\":[{\"type\":\"Column\",\"width\":\"auto\",\"items\":[{\"type\":\"Image\",\"url\":\"https://searchuxcdn.azureedge.net/designerapp/images/servicenow-icon.png\",\"size\":\"Small\",\"horizontalAlignment\":\"Center\",\"altText\":\"ServiceNow logo\",\"$when\":\"https://searchuxcdn.azureedge.net/designerapp/images/servicenow-icon.png!=\\\"\\\"\"}],\"height\":\"stretch\"},{\"type\":\"Column\",\"width\":8,\"items\":[{\"type\":\"TextBlock\",\"text\":\"[${number} ${shortdescription}](${AccessUrl})\",\"color\":\"Accent\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"$when\":\"${shortdescription != ''}\"},{\"type\":\"RichTextBlock\",\"inlines\":[{\"type\":\"TextRun\",\"$when\":\"${sysupdatedby != \\\"\\\"}\",\"text\":\"${sysupdatedby} \",\"weight\":\"Bolder\"},{\"type\":\"TextRun\",\"$when\":\"${sysupdatedby != \\\"\\\"}\",\"text\":\" modified \"},{\"type\":\"TextRun\",\"$when\":\"${sysupdatedon != \\\"\\\"}\",\"text\":\"{{DATE(${sysupdatedon})}}\"}],\"spacing\":\"None\"},{\"type\":\"TextBlock\",\"text\":\"${ResultSnippet}\",\"wrap\":true,\"maxLines\":3,\"spacing\":\"Medium\",\"$when\":\"${ResultSnippet != \\\"\\\"}\",\"color\":\"Dark\"}],\"horizontalAlignment\":\"Center\",\"spacing\":\"Medium\"}]}],\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\"}"

Expanded Adaptive card:

{
    "type": "AdaptiveCard",
    "version": "1.2",
    "body": [
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "auto",
                    "items": [
                        {
                            "type": "Image",
                            "url": https://searchuxcdn.azureedge.net/designerapp/images/servicenow-icon.png,
                            "size": "Small",
                            "horizontalAlignment": "Center",
                            "altText": "ServiceNow logo",
                            https://searchuxcdn.azureedge.net/designerapp/images/servicenow-icon.png!=\\""
                        }
                    ],
                    "height": "stretch"
                },
                {
                    "type": "Column",
                    "width": 8,
                    "items": [
          z              {
                            "type": "TextBlock",
                            "text": "[KB0046925 User Account: How to Send B2B Invites Using the Azure Portal?](https://microsoft.service-now.com/kb_view.do?sys_kb_id=2dfd5689db52cf800c1f546adc9619ed)",
                            "color": "Accent",
                            "size": "Medium",
                            "weight": "Bolder"
                        },
                        {
                            "type": "RichTextBlock",
                            "inlines": [
                                {
                                    "type": "TextRun",
                                    "${sysupdatedby != \"\"}",
                                    "text": "v-preetm ",
                                    "weight": "Bolder"
                                },
                                {
                                    "type": "TextRun",
                                    "${sysupdatedby != \"\"}",
                                    "text": " modified "
                                },
                                {
                                    "type": "TextRun",
                                    "${sysupdatedon != \"\"}",
                                    "text": "{{DATE(2021-07-20T18:52:16Z)}}"
                                }
                            ],
                            "spacing": "None"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${ResultSnippet}",
                            "wrap": true,
                            "maxLines": 3,
                            "spacing": "Medium",
                            "${ResultSnippet != \"\"}",
                            "color": "Dark"
                        }
                    ],
                    "horizontalAlignment": "Center",
                    "spacing": "Medium"
                }
            ]
        }
    ],
    "$schema": http://adaptivecards.io/schemas/adaptive-card.json
}

Sample Code

AdaptiveCardTemplate template = new AdaptiveCardTemplate(templateJsonString);
string cardJson = template.Expand(Source);
AdaptiveCardParseResult cardParseResult = AdaptiveCard.FromJson(cardJson);

Version of SDK

AdaptiveCards.Templating Version="1.2.1"

@jwoo-msft jwoo-msft added this to the 21.08 milestone Aug 6, 2021
jwoo-msft added a commit that referenced this issue Aug 12, 2021
@jonmill jonmill added this to To do in Current Sprint via automation Aug 19, 2021
@jonmill jonmill moved this from To do to Review in progress in Current Sprint Aug 19, 2021
@jonmill jonmill added this to P1 in Triage Aug 20, 2021
@pankajvaher
Copy link
Author

@jwoo-msft any updates on this issue?

@jonmill jonmill removed this from the 21.08 milestone Sep 29, 2021
@RebeccaAnne RebeccaAnne moved this from Review in progress to Reviewer approved in Current Sprint Oct 8, 2021
Triage automation moved this from P1 to Closed Oct 8, 2021
jonmill pushed a commit that referenced this issue Oct 8, 2021
* [.Net] Fixed #6153

* [.NET] Added a unit test and unescaped string for AEL

Co-authored-by: Paul Campbell <paulcam@microsoft.com>
Current Sprint automation moved this from Reviewer approved to Done Oct 8, 2021
@ghost ghost removed the Triage-Approved for Fix label Oct 8, 2021
michaelfarnsworth pushed a commit to michaelfarnsworth/AdaptiveCards that referenced this issue Nov 10, 2022
* [.Net] Fixed microsoft#6153

* [.NET] Added a unit test and unescaped string for AEL

Co-authored-by: Paul Campbell <paulcam@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Triage
Closed
Development

Successfully merging a pull request may close this issue.

4 participants