Open gtonye opened 8 months ago
@ceciliaavila @tracyboehrer would it be possible to triage this item? it is impacting our customers too
Hi @jamesemann, we'll tackle this issue this week.
Hi @gtonye and @jamesemann,
We've been reviewing the issue and debugging the provided bot to find why it is failing with the Bad JSON escape sequence: \(.
error in the regex
property.
Tracking down the problem, it leads to how the JSON prebuilt function receives and parses the AdaptiveCard JSON string value to an object.
The problem is on the double backslash, since the AdaptiveCard JSON is read as a string, the double backslash is being escaped, and when the "string to object" parsing happens, the remaining backslash is interpreted as another escaping character. More information on related issue https://github.com/microsoft/AdaptiveCards/issues/4677.
To solve the issue, you need to provide 4 backslashes in the JSON, as shown in the image below.
@sw-joelmut thank you for the investigation and the very detailed answer! It's very helpful context.
The challenge we have is that it's going to be difficult to expose this constraint to our customers as the corrected regular expression ^\\\\(?([0-9]{3})\\\\)?[-. ]?([0-9]{3})[-. ]?([0-9 ]{4})\\\\ ?\\\\.?$
is invalid both on Regex tester websites like regex101 and the adaptive card designer that I tested with the input:
{"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","type":"AdaptiveCard","version":"1.3","body":[{"type":"TextBlock","text":"Present a form and submit it back to the originator"},{"type":"Input.Text","id":"lastName","placeholder":"1234567890","label":"What is your phone number?","isRequired":true,"errorMessage":"A valid number is required","regex":"^\\\\(?([0-9]{3})\\\\)?[-. ]?([0-9]{3})[-. ]?([0-9 ]{4})\\\\ ?\\\\.?$"}],"actions":[{"type":"Action.Submit","title":"Submit"}]}
Is there any opportunity to enhance or optimize the JSON prebuilt function to make it consistent with the behavior of the adaptive card engine?
Thank you,
Hi @gtonye,
As changing the default behavior of the JSON prebuilt function will break existing customers' bots, we could try adding a flag to treat the AdaptiveCard as it is, without altering its content.
Apologies for the delay @sw-joelmut
we could try adding a flag to treat the AdaptiveCard as it is, without altering its content
That would work great! let me know if you have changes that would need testing. We have several regex samples our customers use that we can share.
Hi team,
Please let me know if you would need additional information, this is currently halting a few use cases in production for us.
Best,
Version
Describe the bug
When adding an adaptive card with escape characters, the bot throws an error:
In the bot code, the following stack trace:
To Reproduce
Expected behavior
The bot should accept the regular expression. It is valid inside the Adaptive Card Designer (with the target version 1.3) as well as valid in https://regex101.com/
Screenshots
Not applicable.
Additional context
Adaptive card I am testing with
https://github.com/microsoft/botbuilder-dotnet/assets/4819282/660c57e9-e7cb-4729-8561-33f3acccd5a2