http://coldfusion.com logo
#box-products
Title
# box-products
m

mburt

03/04/2022, 6:59 PM
Speaking of encoding/decoding, is there a trick when using relocate to prevent a query string from being encoded (or decoded, at this point words no longer have meaning to me 🥴 ) After logging a user in, I’m trying to relocate them back to the exact spot they left off, something like
heroes?ids=1,2,3
but no matter what I try I end up at
heroes?ids=1%252C2%252C3
b

bdw429s

03/04/2022, 7:00 PM
What's wrong with the URL encoded commas?
They should come back into the
url
scope just fine
Oh wait-- it's double encoded
That's your issue
How are you creating the query string?
My guess is your manually encoding something AND ColdBox is encoding it again for you
m

mburt

03/04/2022, 7:04 PM
Yep. Every time you fresh the page, it’s add more and more “stuff”. This is my current attempt, but I’ve also tried `encodeURICompoment`:
Copy code
var customEncodedUrl = window.location.search.replace(
						/\&/g,
						'%26'
					);
b

bdw429s

03/04/2022, 7:04 PM
you'd need to back up and explain how you're redirecting the user
but I can assure you, manually replacing stuff in the string to decode it is NOT the answer 😉
Find out how and where it's getting created and encoded in the first place
Are you redirecting the user via CommandBox's
relocate()
method?
m

mburt

03/04/2022, 7:05 PM
Fair enough, I’m pretty scattered at the moment, let me see if I can put together a more coherent example.
b

bdw429s

03/04/2022, 7:05 PM
Also, have you seen this module https://www.forgebox.io/view/redirectBack
it's made for easy redirects back to the previous page
You litearlly just call
Copy code
redirectBack();
in your ColdBox handler, and it sends the user back to the previous page 🙂
m

mburt

03/04/2022, 7:06 PM
Awesome, I’ll look at that as well.
m

mjclemente

03/04/2022, 7:08 PM
Possibly of note here - Lucee automatically encodes urls when using cflocation: https://luceeserver.atlassian.net/browse/LDEV-2164
👌 1
m

mburt

03/04/2022, 9:02 PM
rubber duck
Copy code
Index.js
---------
...
let fakeUri = encodeURIComponent(`?this=1,2,3&that=4,5,6`);

Inertia.get(`/login?_lastUrl=/orders&_lastQryStr=${fakeUri}`);
...
Moves over the login process in our
Auth.cfc
At this point, if I interupt the process and do a writeDump of
_lastQryString
, it appears decoded (👍). However, if I let it keep going…
Copy code
Auth.cfc
---------
...
relocate(
    url         = rc._lastUrl,
    queryString = rc._lastQryStr
);
...
I end up back where I started (👍) but the query string is now encoded (👎 ) 🤔 • I read up on the cflocation issue, but seeing as we’re using coldbox
relocate()
I’m sure it that situation applies. • I also tried
redirectBack()
but that only got me back to
/orders
without any query string; maybe I just need to play around with it some more.
b

bdw429s

03/04/2022, 9:26 PM
@mburt the rediectback() doesn't use a query string. It uses flash ram. Dump out the
rc
to see what's in it
That said, I'm not entirely following what you're doing with redirects both in JS and in CF
m

mburt

03/04/2022, 9:47 PM
That fair. Thanks for taking a look. I’ll keep at it.
4 Views