Spaces in variable URL

Post Reply
User avatar
Terkelsen
Advanced member
Posts: 300
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Spaces in variable URL

Post by Terkelsen »

I'm using Switch to generate a html-mail containing a button with a URL for the user to click on. This works fine, but if the receiver will forward this e-mail, the URL-link might get lost depending on which e-mail application is used and the users local settings.

To compensate for this I also include the URL as a text string so the user can copy this and paste it in his webbrowser. That works fine as well ..for the most.

The URL is dynamically generated based on metadata from the job i Switch. Sometimes that metadata string will contain spaces (could be a users first and last name). In that case the URL text-string is broken.

I'm aware that in a URL a space is supposed to be %20, but since the data comes from a variable I don't see any way to automatically replace the spaces with %20.

I'm far from an expert in html, so I wonder if anybody has a solution for this challenge.
User avatar
JimmyHartington
Advanced member
Posts: 310
Joined: Tue Mar 22, 2011 7:38 am

Re: Spaces in variable URL

Post by JimmyHartington »

Hi Erik

Could you set the variable to private data?
Then use one of the apps, which can search and replace in private data, to search for space and replace with %20.
And in the e-mail insert the private data url.
User avatar
Terkelsen
Advanced member
Posts: 300
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Spaces in variable URL

Post by Terkelsen »

Brilliant idea, Jimmy :idea: I was on my way down that road, but for some reason turned around.

I simply write the entire URL into Private data and then use String Replace to replace space with %20 in that entire dataset. I've tested and it works just fine :)
User avatar
JimmyHartington
Advanced member
Posts: 310
Joined: Tue Mar 22, 2011 7:38 am

Re: Spaces in variable URL

Post by JimmyHartington »

#UPDATE 2023-09-08 13.57.06: Link to script is changed.
Better logging is added. See this post viewtopic.php?t=4756

Hi Erik

I am still learning to script in Node.JS, so I took this as a small challenge.

Here is a small script, which uses the function "encodeURI" of JavaScript to encode the URL.
https://d.pr/f/6LJBwr+

And here is a sample flow, which also uses Firestarter and Create Text apps.
https://d.pr/f/qt4s7S+

Image
User avatar
Terkelsen
Advanced member
Posts: 300
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Re: Spaces in variable URL

Post by Terkelsen »

Jimmy, I can confirm that your script works as well, just as String replace did :)
Post Reply