Skip to content

Adaptive expression context access with non-standard objects #4860

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

Closed
LeonYasoon opened this issue Feb 25, 2025 · 2 comments · May be fixed by #4876
Closed

Adaptive expression context access with non-standard objects #4860

LeonYasoon opened this issue Feb 25, 2025 · 2 comments · May be fixed by #4876
Assignees
Labels
bug Indicates an unexpected problem or an unintended behavior.

Comments

@LeonYasoon
Copy link

LeonYasoon commented Feb 25, 2025

Versions

What package version of the SDK are you using. 4.23.1
What nodejs version are you using 22
What browser version are you using -
What os are you using macOS

Describe the bug

When providing a non-standard object to $root in AC.expand() when rendering adaptive cards, the context cannot access properties that are in non-standard objects.

To Reproduce

AC.expand({ $root: new DataObjectOfYourChoice({ propertyToAccess: "hasAValue" }) })

AC template: "text": "${propertyToAccess}"

Expected behavior

Text should show "hasAValue", but the property is returned as undefined

Additional context

I tried opening a fix PR for this but i'm unsure of the contribution rules in this repo of if it is even possible. Pushing to a feature branch is not allowed for my git user.

The fix would be in libraries/adaptive-expressions/src/functionUtils.internal.ts lines 221-232:

 const prop: string = Object.keys(instance).find(
      (k: string): boolean => k.toLowerCase() === property.toLowerCase(),
  );
  if (prop !== undefined) {
      value = instance[prop];
  } else if (instance[property] !== undefined || instance[property.toLowerCase()] !== undefined) {
      value = instance[property] ?? instance[property.toLowerCase()];
  }

My change is the else block.

@LeonYasoon LeonYasoon added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Feb 25, 2025
@tracyboehrer tracyboehrer removed the needs-triage The issue has just been created and it has not been reviewed by the team. label Mar 26, 2025
@ceciliaavila
Copy link
Collaborator

Hi @LeonYasoon , we tried reproducing this issue but when we passed a correctly instantiated object to the context, the property was set as expected in the card.
On the other hand, we found a bug related to casing. In JavaScript, property names are case-sensitive. The accessProperty function uses toLowerCase to locate a property, which can produce unexpected results.
In these images you can see both scenarios. Is it possible that the object you are using has a similar condition?

Image

Image

@LeonYasoon
Copy link
Author

LeonYasoon commented Apr 22, 2025

@ceciliaavila Thanks for your thorough testing. In fact, in this minimal repro scenario it does work!

What we have is something similar to this:

Image

Which does still work when testing with this minimal setup.
When opening this ticket i had a case where Object.keys would not return anything for DataObjects which had getters instead of actual class property values, thats why i suggested to fallback to looking in instance.property when Object.key didn't work.
But now i cant reproduce it anymore 🤷

Thanks for investigating and i hope your casing PR gets merged. Might have just been a plain casing issue after all.
If i manage to find the Object.keys issue again i will reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants