0

I have FreeMarker being used on an application running on Windows 7 in a Chinese locale. The .ftl file includes this XML:

<run fontname='Arial'>Æ&#10;</run>

The text is the letter Æ (the grapheme of AE, U+00C6) followed by an encoded newline. There is no FreeMarker text substitution on this line.

After FreeMarker text substitution is run on the file, the XML is changed, losing the ampersand:

<run fontname='Arial'>Æ#10;</run>

Without the ampersand, the encoded newline is lost, and the text "#10;" is displayed instead.

This isn't happening in other Windows systems running with other locales (English, French, German, and most notably Japanese). How can I avoid this, or is this a bug?

DDx
  • 9
  • 4

1 Answers1

0

Looks like the result of some kind of charset disagreement. Ensure that FreeMarker uses the same charset for decoding the template file as the charset actually used for it. (For XML that's usually UTF-8.) If you don't configure FreeMarker to use a specific charset, by default it uses the default charset of the OS, which not what you want usually. Assuming your files are usually in UTF-8, you need to set the default_encoding setting (Configuration.setDefaultEncoding) to utf-8. You can also force the template charset by starting it with <#ftl encoding="utf-8">.

ddekany
  • 29,656
  • 4
  • 57
  • 64