Obscure handling of single quotes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Obscure handling of single quotes

charlbrink
I found an obscure error that for example when I have a template <html th:inline="text" th:remove="tag" xmlns:th="http://www.w3.org/1999/xhtml">[[ #{my.message(${firstName}, ${lastName})} ]]</html> and property my.message={0}''s surname is {1}

then the template is resolved correctly e.g. "John's surname is Smith"

For some reason 3 single quotes is resolved to one single quote, but afterwards variables are not replaced.

Using this property
my.message={0}'''s surname is {1}
the template will be resolved as e.g. "John's surname is {1}"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Obscure handling of single quotes

Metroids
I don't think this is an error... according to what I found, a single quote is used to represent a section within the message pattern that will not be formatted.  And a single quote itself must be escaped by using two single quotes.

So, in your case:

my.message={0}'''s surname is {1}

The first 2 single quotes are replaced with a single single quote, which is output.  The other single quote is the beginning of a section that won't be formatted (and so the variable {0} is not replaced).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Obscure handling of single quotes

charlbrink
Thanks for the explanation, did not know about the purpose of a single quote.

On 20 June 2017 at 07:45, Metroids [via Thymeleaf - User Forum]
<[hidden email]> wrote:

> I don't think this is an error... according to what I found, a single quote
> is used to represent a section within the message pattern that will not be
> formatted.  And a single quote itself must be escaped by using two single
> quotes.
>
> So, in your case:
>
> my.message={0}'''s surname is {1}
>
> The first 2 single quotes are replaced with a single single quote, which is
> output.  The other single quote is the beginning of a section that won't be
> formatted (and so the variable {0} is not replaced).
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://forum.thymeleaf.org/Obscure-handling-of-single-quotes-tp4030555p4030556.html
> To unsubscribe from Obscure handling of single quotes, click here.
> NAML
Loading...