aequos-solutions / modern-data-visualizer

Documentation for the Modern Data Visualizer solution
https://aequos-solutions.github.io/modern-data-visualizer/
7 stars 7 forks source link

[QUESTION] How to escape special characters when using tokens in URLs? #116

Closed d-turley closed 6 months ago

d-turley commented 11 months ago

Version used 1.5.4

Question We have a Data Verticals web part with several verticals configured. We want to be able to carry the user's query text over when they navigate to another vertical, so in the Link URL field we entered a URL like the following:

https://contoso.sharepoint.com/sites/sandbox/SitePages/Search.aspx?q={QueryString.q}&v=Documents

This works in the general case, however if the user types in special characters, for example an ampersand (&) character, in their query then those characters are not properly escaped and the URL is corrupted when navigating.

We then found that we can use Adaptive Expressions, and altered the URL as follows to escape special characters:

https://contoso.sharepoint.com/sites/sandbox/SitePages/Search.aspx?q=${uriComponent(`{QueryString.q}`)}&v=Documents

However, this fails if the user includes the single quote (') character in their search because the {QueryString.q} token is replaced verbatim.

Is there a known way to construct this URL that handles all possible characters a user might enter into the search box? Or is there another way to configure the verticals to meet our requirements?

Laul0 commented 8 months ago

Hi @d-turley,

Did you try the {{escape}} helper?

d-turley commented 8 months ago

What is the {{escape}} helper? Is that handlebars?

We are trying to configure values for the Link URL field in the Data Verticals web part properties panel.

Laul0 commented 8 months ago

https://github.com/helpers/handlebars-helpers#escape

aequosword commented 6 months ago

Because we didn't receive any news from the author of this issue, we closed it. Feel free to open it again if the issue persists.

Thank you