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 card fails to render with specific strings #9392

Open
Wajeed-msft opened this issue Sep 4, 2023 · 2 comments
Open

Adaptive card fails to render with specific strings #9392

Wajeed-msft opened this issue Sep 4, 2023 · 2 comments
Assignees
Labels

Comments

@Wajeed-msft
Copy link
Contributor

Copied bug from: OfficeDev/teams-toolkit#9826

Details from original post:
Describe the bug
Sometimes Teams would show me an error "Error encountered while rendering this message" without any further detail.

To Reproduce
One of the text fields in my adaptive card is supposed to output the following string (actually, a SQL query):

var sql = "SELECT COUNT(DISTINCT VisitorId) AS UniqueVisitors FROM sitedata WHERE eventdate>='2023-08-01' AND eventdate<'2023-08-08' AND Site =='foo.bar.com' AND Url RLIKE '^http?s://foo.bar.com/([^/]*)/answers/?'"

To render the card I'm using this code:

var cardContent = new AdaptiveCardTemplate(cardTemplate).Expand(
			new
			{
				Query = sql
			}
		);

		var replyActivity = MessageFactory.Attachment
		(
			new Attachment
			{
				ContentType = "application/vnd.microsoft.card.adaptive",
				Content = JsonConvert.DeserializeObject(cardContent),
			}
		);

		await turnContext.SendActivityAsync(replyActivity);

The card's relevant portion is this:

{
      "type": "TextBlock",
      "text": "${query}",
      "wrap": true,
      "fontType": "Monospace",
      "color": "Dark",
      "horizontalAlignment": "Left",
      "separator": true
    }

Steps to reproduce the behavior:
Send the adaptive card and Teams will show that it fails to render the card. There is no exception.

Expected behavior
Card is rendered fine without error.

VS Code Extension Information (please complete the following information):
Teams web or client, both Mac and Windows

Additional context
I tried to figure out what exactly it is that breaks the rendering but the results are non-conclusive.
By trial and error I started removing bits from the SQL string and found that it will still fail with this reduced version of the original string:

"SELECT COUNT(DISTINCT VisitorId) AS UniqueVisitors FROM sitedata WHERE eventdate>='2023-08-01' AND"

However, if I change it further and only remove the last AND, it renders just fine:

"SELECT COUNT(DISTINCT VisitorId) AS UniqueVisitors FROM sitedata WHERE eventdate>='2023-08-01'"

As a workaround I wrapped the assignment into WebUtility.HtmlEncode(sql)and that fixes the issue. This will however break potential formatting such as Markdown.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

@sayali-MSFT
Copy link

@Krumelur - Thanks for reporting your issue.
We will check this at our end and will get back to you.

@sayali-MSFT sayali-MSFT self-assigned this Sep 4, 2023
@sayali-MSFT
Copy link

@Krumelur - We are able to repro that issue, we have raised bug for the same. We will inform you once we get any update.
Microsoft Teams Version 1.6.00.24965 (64-bit).

@sayali-MSFT sayali-MSFT added the bug label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants