Aptana 3 - CFEclipse - .cfm file - UTF-8 encoding incorrect

1.1k views Asked by At

I have created the following .cfm file using the CFML editor of CFEclipse in Aptana 3:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>templates</title>

</head>

<body>
£
</body>
</html>

My Workspace encoding is set to UTF-8, but when I save and view the file in a browser my pound sign has changed to £.

I can resolve the problem by adding

<cfprocessingdirective pageencoding = "utf-8"/>

to the top of my CFM file but for the website I am working on I can't realisticly do that for every page and I've tried adding it to the page header include but that doesn't work.

If I save the file as HTML file or save the file using notepad utf-8 the pound sign is fine, so it seems to be related to the CFML editor of the CFEclipse plugin in Aptana. Has anyone come across this issue before or have any ideas on how to resolve it?

Thanks

EDIT (Added charset headers) :

HTTP/1.1 200 OK
Date: Thu, 06 Oct 2011 13:26:11 GMT
Server: Apache/2.2.17 (Win32) PHP/5.3.4 JRun/4.0
Set-Cookie: CFGLOBALS=urltoken%3DCFID%23%3D12703%26CFTOKEN%23%3D40776140%23lastvisit%3D%7Bts%20%272011%2D10%2D06%2014%3A26%3A11%27%7D%23timecreated%3D%7Bts%20%272011%2D10%2D04%2017%3A05%3A01%27%7D%23hitcount%3D314%23cftoken%3D40776140%23cfid%3D12703%23;expires=Sat, 28-Sep-2041 13:26:11     GMT;path=/
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

GET /enc_test3.cfm HTTP/1.1
Host: www.foo.co.uk
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
3

There are 3 answers

3
mz_01 On

Try putting

<cfprocessingdirective pageencoding="utf-8" />

near the top of your Application.cfc

1
Sergey Galashyn On
My Workspace encoding is set to UTF-8, but when I save and view the file in a browser my pound sign has changed to £. 

Obviously, your crated .cfm files are not really UTF8. CFEclipse does not handle file encoding, at least I haven't seen such settings for it. But Eclipse has ability to define encoding per resourse (File/Properties), is there such thing in Aptana (haven't used it for a while)?

2
Adam Cameron On

You have no choice. If you have UTF-8 (or, basically, any "non-ASCII" ~) content in your CFM files, you need to tell the CF compiler how the file is encoded (with CFPROCESSINGDIRECTIVE, as you have done).

As this needs to be done at compile time, it cannot work by putting a tag in your Application.cfc or any "upstream" CFM file, because the "unstreamedness" is determined at runtime, not compile time.

On the whole, it should be a rarety that you have non-ASCII text in a CFM file because a CFM should be pretty much code, not content or data. That said, I realise this is not always possible.