Re: URL encoding and the "+" char
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Wednesday, June 2, 2010, 10:17:14 AM, Attila Szegedi wrote:
> In a somewhat related question, any idea why do we have
> StringUtil.URLEnc and are not simply using java.net.URLEncoder?
Yes, it has two reasons: Before J2SE 1.4 that class was pretty much
useless (as it didn't let you specify the charset), and 2.3 doesn't
require 1.4 yet. Then, java.net.URLEncoder converts space to "+" (not
to "%20"), which is fine or even preferablein in query parameter
values (the primary usage of ?url), but fails when used in the path
part of URL-s, so using "+" could lead to some mean hard-to-hit bugs
in your applications. (Funny, isn't it? I mean, dear IETF, could it be
a bit more complicate please? A poor little escaping? Come on... You
also have, like, 4 kind of escaping in XML if you want to keep things
as short as possible. So mostly you just end up having one
über-escaper that escapes everything like crazy (BTW, startin from 2.4
we will escape "aposthrophe" quotation marks in ?html as well, as
&#...; really works everywhere nowadays), and then one to be used
inside CDATA sections... except that everyone used to forget about the
last. Including us, BTW, but since FM is not XML-aware and users would
never remember writing ${stuff?cdata}, it doesn't mater much in
practice.)
> Attila.
>
> On 2010.06.02., at 9:54, Daniel Dekany wrote:
>
>> Wednesday, June 2, 2010, 12:08:39 AM, Dan Washusen wrote:
>>
>>> Hey All,
>>> I'm attempting to add a base64 encoded string as a URL parameter in a FM template.
>>>
>>> <a id="activate" href="action?token=${token?url}">Click Here</a>
>>>
>>> This works fine but it appears that the Freemarker URL encoding
>>> doesn't encode the "+" chars contained in the token. When I attempt
>>> to decode the token using either commons-codec or the
>>> java.util.URLDecoder the "+" is replaced by a space (" ") and my token is corrupt.
>>>
>>> So I guess my question is; is this a bug or a feature?
>>
>> That would be a major bug, as ?url is for escaping query parameters.
>> But for me it works. This is the template I tried:
>>
>> <#setting url_escaping_charset='utf-8'>
>> ${.version}
>> ${"a/b+c d"?url}
>>
>> and its output was:
>>
>> 2.3.16
>> a%2Fb%2Bc%20d
>>
>> What is the output on your setup? (Note that I didn't even find any
>> version history entry that says that ?url had a bug in earlier
>> FreeMarker versions.)
>>
>>> Cheers,
>>> Dan
>>
>> --
>> Best regards,
>> Daniel Dekany
>
>
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------