[MAGNOLIA-3286] Add new setting URLEscapingCharset to the freemarker config Created: 31/Aug/10  Updated: 06/Dec/13  Resolved: 06/Dec/13

Status: Closed
Project: Magnolia
Component/s: freemarker
Affects Version/s: 4.3.6
Fix Version/s: 4.5.11, 5.1

Type: Improvement Priority: Neutral
Reporter: Bert Leunis Assignee: Ondrej Chytil
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File magnolia-core.patch    
Issue Links:
duplicate
duplicates MAGNOLIA-3739 Freemarker ?url builtin doesn't work ... Closed
relation
is related to MAGNOLIA-1469 Make Freemarker more configurable thr... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:

 Description   

Since Freemarker 2.3.1 a new built-in exists: ?url for url escaping: see http://freemarker.sourceforge.net/docs/ref_builtins_string.html#ref_builtin_url. For this built-in to work the charset has to be set. That can be done in tree ways:

1. as a parameter of the built-in itself: ${x?url('UTF-8')}
2. add a setting to a template: setting url_escaping_charset="UTF-8"
3. add the setting to the freemarker config.

The patch added takes care of option 3.



 Comments   
Comment by Bert Leunis [ 31/Aug/10 ]

Further ways to make the freemarker config in magnolia more flexible and configurable were described by Grégory on the userlist:

As far as I can tell, there are basically 3 approaches: 1) we simply add cfg.setURLEscapingCharset("UTF8"); next to cfg.setDefaultEncoding("UTF8");
2) we make both of these configurable via admincentral
3) we make ALL config properties configurable via admincentral by using freemarker.core.Configurable#setSetting

Option three gives the most freedom, but takes more time to build.

Comment by Magnolia International [ 01/Sep/10 ]

Is UTF-8 the good default for url encoding? I'm not sure why it even needs to be specified; isn't that supposed to be the encoding of the source files (.ftl) ? and/or of the variable it uses ?

Comment by Fabrizio Giustina [ 01/Sep/10 ]

Is UTF-8 the good default for url encoding?

The default for url encoding is ISO-8859-1. Using UTF-8 is better but you usually have to configure the application server appropriately before, using UTF-8 with the default configuration may lead to strange results. (Speaking about tomcat, you have to set the encodingURI on the connector and the "forward request unparsed" thing on the apache side).
Url encoding in standard servlet methods/ jsp tags use ISO-8859-1, e.g. c:redirect tag encodes URLs using ISO-8859 (and breaks if you have UTF-8 urls).

So, utf-8 is definitively the best default for people that need extended chars in URLs but it also requires some tweak on the environment, not sure if everybody is aware of that.

Comment by Magnolia International [ 10/Jan/11 ]

Can we get this into 4.4.2 with the value configured under /server/rendering/freemarker ?

Comment by Philipp Bärfuss [ 18/Jan/11 ]

We are finalizing 4.4.2 hence I am moving this issue to 4.4.3.

Comment by Magnolia International [ 06/Dec/13 ]

Fixed with MAGNOLIA-3739

Generated at Mon Feb 12 03:45:01 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.