Follow

Issues with Links Encoding

When you write a normal link and personalize some parts, like this:

 

<a href=”http://www.repsolution.com/index.php?first_name=[[=Contact.f_FirstName;]]”>

 

Then the system will automatically url_encode the Contact.f_FirstName variable, so that “Jean-Stéphane” will come out as “Jean-Stéphane” more or less (i.e. the “é”, url_encoded for utf-8). This is the default behavior and is, obviously, absolutely necessary otherwise “all hell would break loose” when passing parameters.

 

Now, other times, you have fun stuff like “a variable that contains a complete path”. Here, it gets interesting. The actual question is: What do you actually want to do with that variable?

 

Two possible cases:

 

CASE A)

 

You want to send that URL as a PARAMETER to a site. A very simple and common case of this is when you want to send the client to a specific page, but actually need to send him to a  login screen first, so you need to send him to a link that looks like this:

 

http://ofsys.com/login.aspx?ReturnUrl=%2fDefault.aspx

 

So imagine that in OFSYS, you have this:

 

<a href=”http://ofsys.com/loginpaspx?ReturnUrl=[[=Contact.f_StatsPage;]]”>

 

No choice here, f_StatsPage must be url_encoded or the link will break. The default behavior of the Openfield system will make this work.

 

However…

 

CASE B)

 

Now, other times, you actually have a variable that contains an actual path, that you want to redirect to as-is, without any encoding. Let’s assume (as is your case here) that Contact.f_ModelURL contains a full URL you want to redirect to. Obviously, if we encode it, we’ll create a broken link. So we’ve created a special case just for that.

 

When a link contains only a single personalization statement, i.e. [[=…;]], then the system will go “ok, this guy’s building his own link. Let’s assume he knows what he’s doing, and we’re not going to encode anything”.

 

That is why your first example works:

 

<a href=”[[=Contact.f_ModelURL;]]”>

 

This triggers the special rule, and your link is used as-is. When you add the “?” after the personalization statement however, the rule isn’t matched anymore, so the variable is encoded, and your link is broken. So… the simple solution is to make sure your link is limited to a single [[=…;]] statement when it’s a full URL. What’s INSIDE that statement can be a lot more complex however, so let’s say what you wanted to do is this:

 

<a href=”[[=Contact.f_ModelURL;]]?f_FirstName=[[=Contact.f_FirstName;]]”>

 

This will not work as previously mentioned, but you can still match the special rule by doing this:

 

<a href=”[[=Contact.f_ModelURL + “?f_FirstName=” + System.Encoding.URL(Contact.f_FirstName, “utf-8”);]]”>

 

This is a single personalization statement so it matches the rule, and here we manually url_encode the last value for utf-8, so that Jean-Stéphane still comes out as Jean-Stéphane. The final link for this will be:

 

http://www.yourclient.ru/page.php?f_FirstName=Jean-Stéphane

 

 

Hope this helps!

 

Overall rule is:

 

  • ·         Normal link with injected personalization tags = all parameters will be encoded (utf-8 usually, based on your project’s config)
  • ·         Link made up of nothing but one single personalization tag = nothing is encoded (but that does mean you need to explicitly encode anything that needs to be encoded).

6 Comments

  • Avatar
    Ofsys Master

    |

    What you want   to do?

    |

    Example

    |

    What Ofsys will   do

    |

    Comments

    |
    |

    You write a normal link and want to   personalize some parts with a value of a field.

    Rule : Normal link with injected   personalization tags = all parameters will be encoded (utf-8 usually, based   on your project’s config)

    |

    <a href=” [http://www.intelligentemails.ru/index.php?first\_name=[[=Contact.f\_FirstName;]]](http://www.intelligentemails.ru/index.php?first_name=%5b%5b=Contact.f_FirstName;%5d%5d)”>

     

    |

    Then, Ofsys will automatically   url_encode the Contact.f_FirstName variable

    |

    “Jean-Stéphane” will come out as   “Jean-St%C3%A9phane”.

     

    |
    |

    You want to send an URL as a PARAMETER   to a site like [[=Contact.f_StatsPage;]] which contains a full path.

     

    |

    <a href=” [http://intelligentemails.ru/loginpaspx?ReturnUrl=[[=Contact.f\_StatsPage;]]](http://intelligentemails.ru/loginpaspx?ReturnUrl=%5b%5b=Contact.f_StatsPage;%5d%5d)”>

     

    |

    The default behavior of Ofsys system   will make this work.

    |

    f_StatsPage must be url_encoded or the   link will break.

    |
    |

    You want to actually have a variable   that contains an actual path, that you want to redirect to as-is,   without any encoding.

    Something like:

    <a   href=”[[=Contact.f\_ModelURL;]]?f\_FirstName=[[=Contact.f\_FirstName;]]”>.    But When you add the “?” after the personalization statement however, the   rule isn’t matched anymore, so the variable is encoded, and your link is   broken.

    |

    <a href=”[[=Contact.f\_ModelURL +   “?f\_FirstName=” + System.Encoding.URL(Contact.f\_FirstName, “utf-8”);]]”>

     

    <a   href="[[=Contact.f\_ba\_hotelurl + "&utm\_campaign=booking\_attempts&userID="   +System.Encoding.URL(Contact.f\_User\_id , "utf-8");]]"> URL   </a>

    |

    Ofsys will not encode.

    |

    Rule : when a link contains only a   single personalization statement, i.e. [[=…;]], then the system will go :

    “ok, this guy’s building his own link,   let’s assume he knows what he’s doing, and we’re not going to encode   anything”.

    |
    |

     

    |

     

    |

     

    |

     

    |
    |

     

    |

     

    |

     

    |

     

    |
    |

    Rule1

    |

    Normal link with injected personalization   tags = all parameters will be encoded (utf-8 usually, based on your project’s   config)

    |

     

    |

     

    |
    |

    Rule2

    |

    Link made up of nothing but one single   personalization tag = nothing is encoded (but that does mean you need to   explicitly encode anything that needs to be encoded).

    |

     

    |

     

    |
    |

    Additional resources about links   encoding

    |

    http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

    |

     

    |

     

    |
    |

    Encoder / decoder

    |

    http://www.albionresearch.com/misc/urlencode.php

    |

     

    |

     

    |
    |

     

    |

     

    |

     

    |

     

    |

  • Avatar
    Ofsys Master

    ANOTHER EXAMPLE

    QUESTION :

    The construct

     

    <a href= http://ostrovok.ru/[[=Contact.f_hotel_url;]]

     

    becomes  http://ostrovok.ru/%2fhotels%2fglobal%2finfo%2f188142%2f

     

    where value of hotel_url is /hotels/global/info/188142

     

    How to write it in Message?

     

    ANSWER :

    If the content of the “href” attribute of your link is ANYTHING other than a SINGLE [[=…;]] statement, then the system will assume that you are adding parameters to a link and will encode all customization values accordingly.

     

    Which is why this:

     

    <a href=" [http://ostrovok.ru/[[=Contact.f\_hotel\_url;]]](http://ostrovok.ru/%5b%5b=Contact.f_hotel_url;%5d%5d)">

     

    Gets encoded, because your href contains " http://ostrovok.ru/”  and [[=Contact.f_hotel_url;]].

     

    What you want is:

     

    <a href="[[= " [http://ostrovok.ru/](http://ostrovok.ru/)" + Contact.f\_hotel\_url; ]]">

     

    Since THAT link is a single “Equal” statement i.e. [[=…;]] then the system will assume you are building a complete URL yourself and that you will handle encoding on your own.

  • Avatar
    Mike LYADOV

    Specific example of encoding links with dynamic content: 


    This link contains two dynamic tags, but this syntax is incorrect

    <a  href="[[=Product.Product\_LinkURL;]]?sdfrty=[[=Contact.f\_auth;]]">

    If your data includes the URL itself, i.e. anything other than just PARAMETERS added into a link, then you must use ONE and ONLY ONE [[=…;]] statement in your link.

    Anything else, and the system will assume you are just customizing a normal link with parameters, and it will URLENCODE all custom values.\

    When a link (the ENTIRE content inside the href element) consists of a SINGLE [[=…;]] statement and NOTHING ELSE, then the system will assume that you are building your own link from scratch, and will NOT encode anything, letting you decide what gets encoded and how.

    What you need to do then is this:

    <a  href="[[=Product.Product\_LinkURL + "sdfrty" + Contact.f\_auth;]]">

  • Avatar
    Mike LYADOV

    To include email use 

    <a href=" [mailto:[[=Contact.f\_EMail;]]](mailto:[[=Contact.f_EMail;]])">

    not 

    <a href="[[=Contact.f\_EMail;]]">

  • Avatar
    Ofsys Master

    <a target="\_blank" href="[[=Product.Product\_LinkURL;]]?sdfrty=[[=Contact.f\_auth;]]">

     

    If your data includes the URL itself, i.e. anything other than just PARAMETERS added into a link, then you must use ONE and ONLY ONE [[=…;]] statement in your link.

    Anything else, and the system will assume you are just customizing a normal link with parameters, and it will URLENCODE all custom values.

     

    In your example, “Product.Product_LinkURL contains  this:

     

    https://www.yourcompany.ru/f1173808

     

    and Contact.f_Auth usually contains a string that looks like ABCDEF

     

    When this gets encoded into the link the final URL that the contact is being redirected to becomes this:

     

    https%3a%2f%2fwww.yourcompany.ru%2f1173808?sdfrty=ABCDEF

     

    And since that is used as a “redirection URL” when the person clicks the actual link in the message, the browser does NOT see it as an actual URL (it does NOT start with http://), just as what looks like a file name for a web page, and it this it is a relative link, which is why it only replaces the last part of the router link with that block.

     

    This is why we created the special case I described a few times:

     

    When your link (the ENTIRE content inside the href element) consists of a SINGLE [[=…;]] statement and NOTHING ELSE, then the system will assume that you are building your own link from scratch, and will NOT encode anything, letting you decide what gets encoded and how.

     

    What you need to do then is this:

     

    <a target="\_blank" href="[[=Product.Product\_LinkURL + "sdfrty" + Contact.f\_auth;]]">

     

    And NOTHING will be encoded, so your end result will be a redirection to:

     

    https://www.yourcompany.ru/f1173808?sdfrty=ABCDEF

     

    Which your browser will see as a full URL and redirect correctly.

     

    _Note that in this case if you NEED to encode something, you need to do it by hand. _

     

    Let’s pretend you want to add the first name, which will likely be in Russian and needs to be encoded to UTF-8. You’d do this:

     

    <a target="\_blank" href="[[=Product.Product\_LinkURL + "sdfrty" + Contact.f\_auth + "&firstname=" + System.Encoding.URL(Contact.f\_FirstName ,"utf-8");]]">

     

    This will encode the first name before adding it to the string, making sure the server receives proper utf-8 data.

  • Avatar
    Ofsys Master

    Another example :

    QUESTION:

    The final link we need to have:  http://st.yourcompany.ru/upload/iblock/b76/resized_ut000055110.jpg

    The harcoded part:  http://st.yourcompany.ru/upload/iblock/

    The part that will be placed in the field: b76/resized_ut000055110.jpg

     

    ANSWER: 

    <a href="[[=" [http://st.yourcompany.ru/upload/iblock/](http://st.zapato.ru/upload/iblock/)" + product.Product\_URL;]]"> click me </a>

     Notes:

    • The fact that HREF of the link contains ONLY one bloc [[=…;]] creates a parsing of links in mode "the programmer knows perfectly what he's doing and nothing is encoded without his permission".
    • Because content is with no risk here, (no freform text, just URL fragments), it's just a matter of concaténation of fragments together.

     

     

Please sign in to leave a comment.