question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[.NET][Templating] Expand function doesn't handle strings with escape characters

See original GitHub issue

Platform

What platform is your issue or question related to? (Delete other platforms).

  • .NET (Templating nuget)

Author or host

Author / Host

If you’re an author, who are you sending cards to? 1.2.9

What version are you using? Ex: NuGet 1.0.2, or latest main, etc… Templating nuget release candidate

Explain your issue. If you just have a question, please post on StackOverflow instead:

  • When expanding a templated json with a concrete type, any strings within that type that contain escape characters \ or " will break the json parser.

Example:

Given this template

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2",
    "body": [
        {
            "type": "TextBlock",
            "text": "${title}"
        }
    ]
} 

And expanding with a concrete type with Property

[JsonProperty("title")]
Title => return "Hello \ world";

Will result in a parsing error when the card is expanded and result in no card being displayed.

We’re currently working around this issue by manually escaping all strings we use, but it would be great if the templating system could handle strings that contain escape characters.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nimercercommented, Aug 21, 2020

Hi @arvindkannan - the workaround I used was to write my own custom Adaptive Expression and replace the escape string characters

                AdaptiveExpressions.Expression.Functions.Add("stringFormat", (args) =>
                {
                    string returnVal = args[0] ?? string.Empty;
                    returnVal = returnVal.Replace(@"\", @"\\").Replace(@"""", @"\""");
                    return returnVal;
                });

then use that inside my template like this:

               "text": "${stringFormat(stringToReplace)}"
0reactions
RebeccaAnnecommented, Sep 9, 2021

Please reactivate if you’re still seeing this issue in the latest templating package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Process escape sequences in a string in Python
The plan is, we'll find escape sequences using a regular expression, and use a function as the argument to re.sub to replace them...
Read more >
eval doesn't handle terminal escape sequences correctly
Version: 3.0.0 I am trying to call eval echo "[green]blah [red]$foo[black]" where [green] etc are terminal escape sequences. eval throws the ...
Read more >
How to escape special characters in a string?
You don't need to escape any file names you are handling in a script. Escaping is only necessary if you want to put...
Read more >
bash: how to pass command line arguments containing ...
In bash, double-quoting does not bypass expanding variables "$HOME" or parameters "${USER:-root}" , command substitution in either form "$(date) ...
Read more >
Preventing Escape Sequence Interpretation in Python
If a match is found then the sequence is omitted from the string, ... The repr() function does not interpret the escape sequence...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found