I am getting an error in Hubspot while trying to decode a URL. I get the feeling this is just an issue with the Hubsopt code validator.
{% set encoded_url = request.query %}
<h5>encoded: {{ encoded_url }}</h5>
{% set decoded_url = encoded_url|b64decode %}
<h5>decoded: {{ decoded_url }}</h5>
On the decode part, I get the following error and can’t publish the module.
“input byte array has wrong 4-byte ending unit”
The test below works which is essentially doing the same thing.
{% set myurl = 'yacht=485982377&status=charter¤cy=USD&poa=no&vat_paid=no&broker=453230516&branded=yes&event=YACHT-SHOW' %}
{% set encoded_url = myurl|b64encode %}
<h3>encoded: {{ encoded_url }}</h3>
{% set decoded_url = encoded_url|b64decode %}
<h3>decoded: {{ decoded_url }}</h3>
I need to be able to store the URL in a variable and decode it. Any ideas on what to do?
Hi @SStrachan1
I presume that the value of request.query is already encoded in base64. For me, as you’re working with dynamical values hubspot validator is displaying an error because is unable to know that request.query contains encoded values.
I’ll do it in a different way. In your template, define the following variable:
{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}
In your page, in the advanced section in the settings place the following declaration in the head rich_text:
{% set encoded_url = request.query %}
That should solve your problem but it also could be a little forbidding if you have a lot of pages.
Have a nice day!
Matthieu
Hey @MBERARD Thanks for the reply.
I am still getting the same “input byte array has wrong 4-byte ending unit” error with this code:
{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}
Can you please pprint encoded_url and post the results?
Here you go.
(String: eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X=)
I believe the = at the end is being added automatically.
I think you find the problem. If you encode in base64 your query:
yacht=485982377&status=charter¤cy=USD&poa=no&vat_paid=no&broker=453230516&branded=yes&event=YACHT-SHOW
You get the following results:
eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X
So it’s probably an interpretation of your browser as he consider the encoded query as a key instead of the whole value. You should probably update your URL with the following structure:
https://www.your-current-url.com/page?q=eWFjaHQ9NDg1OTgyMzc3JnN0YXR1cz1jaGFydGVyJmN1cnJlbmN5PVVTRCZwb2E9bm8mdmF0X3BhaWQ9bm8mYnJva2VyPTQ1MzIzMDUxNiZicmFuZGVkPXllcyZldmVudD1ZQUNIVC1TSE9X
Then update your code with the following declaration:
{% set encoded_url = request.query_dict.q %}
That did the trick. I had that earlier, but no this:
{% set decoded_url = encoded_url is none ? "" : encoded_url|b64decode %}
That is what was needed. Thank you for your halp!