Encoding in variable

I am sending the url to my server connect but the forward slashes are kind of encoded with a backslash before it..
This is the url /myurl/somedir/another dir/ and that is what I need, but is is received by the SC component as \/myurl\/somedir\/another dir\/

Is there a solution for this?
I also tried to replace them in a string replace function but I could not get it working.

Could you provide a screenshot of the method used to pass in the url, and a screenshot of the server connect section receiving it?

Hi GraybeardCoder,

sure: I bind the browser pathname as an input variable:
image

image

And in the SC api I retrieve it in the $_GET section:
image

I then take a Set Value and output the value:
image

When I check the value in the browser I get this:
image

Does this make it clear?

The issue is probably related to the encoding of forward slashes (/) being escaped with a backslash (\) when passing the URL string to the script due to JSON encoding.
So why isn't is decoded in the SC, and how can this be done?

Perfectly clear, thank you for the images. I would have done it exactly the same. In other posts, you appear to be using PHP for your server-side scripting. Passing a string with a forward slash in a URL parameter, is most likely being encoded by PHP at runtime, server-side. This is because the server-side PHP framework thinks you wouldn't want it to be interpreted as a path separator, as that could be risky. But this is exactly what you're hoping to do.

My suggestion is to not pass parameters over $_GET with path separators "/". If there's a specific part of the path you need to know server-side, pass that specific part of the path over the URL. There's a 'rawurldecode' function in PHP. Do you see that as a formatter option server-side when looking at your Set Variable step?

There are also a lot of text formatters available in Wappler server-side. If you just need a specific part of the path in your SC API, then you could try various approaches to getting the specific part of the path that matters. If you need the entire path, then there's a decision on where to split it up: client-side with multiple URL key=value pairs, or server-side using the text formatters to remove the backslashes.

1 Like

Thanks @GraybeardCoder you put me on the right direction.
I used a split function on the path to change the slashes to comma's.

This works good; I receive it as it was send, with comma seperated values instead of slashes.

So now all I have to do is changes these comma's into slashes again, simple right?

So I created a new Set Value with the replace formula: pathname.replace(',', '/')

But #$%&#@# again it escapes the slashes with backslashes:
image

Is there now way to use slashes in a string without it being escaped?

@Teodor do you have a solution?

What server model are you using?

I'm using PHP

What is the exact expression you're sending from your page via the GET param? Do you modify the pathname when binding it to the server action on the page?

Look here Teodore:

But it is the normal way to send this value to the backend - it's escaped.
The backend (Server connect) handle these escaped slashes without issues. Even if you try to output the value on the page it will be correct. You can also see it in the Preview tab in the browser (left of the Response)

Ah alright...
So the Preview tab shows the actual values used by the scripts?

It is because when I test the database query in Wappler with the Test Value for the condition parameter it works fine but with on the live server I get no results:


Here you see the path varable holds the same value as the Test Value:
image

Make sure to disable the Debug option on the database query step, so you can see the results it returns.

1 Like

Oh yes! That helps :sweat_smile:...
So it's normal the debug setting does not return any results?

Now it's finally working.

Sorry, I feel such a noob. Thanks!!

The debug mode on the database query steps returns the sql query for debugging purposes.

1 Like