microsoft / botbuilder-dotnet

Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
https://github.com/Microsoft/botframework
MIT License
878 stars 484 forks source link

AdaptiveCards.Templating 2.0.0 fails to parse payload with json-like strings #6814

Closed MaceWindu closed 4 months ago

MaceWindu commented 4 months ago

Version

AdaptiveCards.Templating 2.0.0

Describe the bug

After migration from 1.5.0 to 2.0.0 templates with data containing json-like strings fail to render

To Reproduce

        var template = @"{
    ""type"": ""AdaptiveCard"",
    ""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"",
    ""version"": ""1.5"",
    ""body"": [
        {
            ""type"": ""Container"",
            ""items"": [
                {
                    ""type"": ""FactSet"",
                    ""$data"": ""${indicesAndValues(Properties)}"",
                    ""facts"": [
                        {
                            ""title"": ""1"",
                            ""value"": ""2""
                        }
                    ]
                }
            ]
        }
    ]
}";
        var cardTemplate = new AdaptiveCardTemplate(template);

        var props = new Dictionary<string, object?>()
        {
            {
                "Properties",
                new Dictionary<string, object?>()
                {
                    { "json-like-string",  "{\"one\":2}" }
                }
            }
        };

        cardTemplate.Expand(props);

Expected behavior

Works as before or better

Additional context

System.Exception
  Message=Invalid expression format.
  Source=AdaptiveCards.Templating
  StackTrace:
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.PushTemplatedDataContext(String jpath) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 167
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitTemplateData(TemplateDataContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 199
   at AdaptiveCardsTemplateParser.TemplateDataContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 260
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitObj(ObjContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 289
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitValueObject(ValueObjectContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 271
   at AdaptiveCardsTemplateParser.ValueObjectContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 359
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitArray(ArrayContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 482
   at AdaptiveCardsTemplateParser.ArrayContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 316
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitChildren(IRuleNode node) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 517
   at AdaptiveCardsTemplateParserBaseVisitor`1.VisitValueArray(ValueArrayContext context) in -\AdaptiveCardsTemplateParserBaseVisitor.cs:line 64
   at AdaptiveCardsTemplateParser.ValueArrayContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 563
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitChildren(IRuleNode node) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 517
   at AdaptiveCardsTemplateParserBaseVisitor`1.VisitJsonPair(JsonPairContext context) in -\AdaptiveCardsTemplateParserBaseVisitor.cs:line 24
   at AdaptiveCardsTemplateParser.JsonPairContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 212
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitObj(ObjContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 330
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitValueObject(ValueObjectContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 271
   at AdaptiveCardsTemplateParser.ValueObjectContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 359
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitArray(ArrayContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 482
   at AdaptiveCardsTemplateParser.ArrayContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 316
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitChildren(IRuleNode node) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 517
   at AdaptiveCardsTemplateParserBaseVisitor`1.VisitValueArray(ValueArrayContext context) in -\AdaptiveCardsTemplateParserBaseVisitor.cs:line 64
   at AdaptiveCardsTemplateParser.ValueArrayContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 563
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitChildren(IRuleNode node) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 517
   at AdaptiveCardsTemplateParserBaseVisitor`1.VisitJsonPair(JsonPairContext context) in -\AdaptiveCardsTemplateParserBaseVisitor.cs:line 24
   at AdaptiveCardsTemplateParser.JsonPairContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 212
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitObj(ObjContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 330
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitValueObject(ValueObjectContext context) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 271
   at AdaptiveCardsTemplateParser.ValueObjectContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 359
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardsTemplateVisitor.VisitChildren(IRuleNode node) in AdaptiveCards.Templating\AdaptiveCardsTemplateVisitor.cs:line 517
   at AdaptiveCardsTemplateParserBaseVisitor`1.VisitJson(JsonContext context) in -\AdaptiveCardsTemplateParserBaseVisitor.cs:line 14
   at AdaptiveCardsTemplateParser.JsonContext.Accept[TResult](IParseTreeVisitor`1 visitor) in -\AdaptiveCardsTemplateParser.cs:line 35
   at Antlr4.Runtime.Tree.AbstractParseTreeVisitor`1.Visit(IParseTree tree) in Antlr4.Runtime.Tree\AbstractParseTreeVisitor.cs:line 9
   at AdaptiveCards.Templating.AdaptiveCardTemplate.Expand(EvaluationContext context, Func`2 nullSubstitutionOption) in AdaptiveCards.Templating\AdaptiveCardTemplate.cs:line 68
   at AdaptiveCards.Templating.AdaptiveCardTemplate.Expand(Object rootData, Func`2 nullSubstitutionOption) in AdaptiveCards.Templating\AdaptiveCardTemplate.cs:line 78
tracyboehrer commented 4 months ago

This should be opened in https://github.com/microsoft/adaptivecards

However, they indicated updating to 2.0 is not required, and to mitigate by staying on 1.5. For further information, please open an issue in that repo.

MaceWindu commented 4 months ago

Thanks, looks like filled on wrong tab. In any case looks like AdaptiveCards team released fix for it