2

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
eb_Dev
  • 873
  • 2
  • 13
  • 25
  • Is your web server setting any conflicting charset headers? – Peter Boughton Oct 06 '11 at 13:24
  • I don't think so, unless the test is case sensitive? I've included the page request headers, is that enough to check? – eb_Dev Oct 06 '11 at 13:35
  • The request headers wouldn't be enough, but since you also added the _response_ headers, that's enough. ;) I'm not aware of any case issues, but I was more thinking you might be on IIS and that was shoving an iso-8859 header in there - but that's not the case. – Peter Boughton Oct 06 '11 at 14:22
  • Another thought - have you tried this in multiple browsers/machines - does the £ get corrupted in all of them? – Peter Boughton Oct 06 '11 at 14:23
  • I hadn't tried it on other browsers but having just checked the issue is the same on them as well. I don't have another machine to test on. unfortunately. – eb_Dev Oct 06 '11 at 14:34
  • You may have tried this because it is easy to Google, but there's additional encoding setting for content-type https://aptanastudio.tenderapp.com/discussions/problems/912-utf-8-encoding-on-mac-os-x#comment_962087 – Sergey Galashyn Oct 06 '11 at 17:11
  • thanks Sergii but yeah I already tried that :( thinking I'm just going to have to put in all the affected files. – eb_Dev Oct 07 '11 at 13:44
  • I would change my editor in this case... – Sergey Galashyn Oct 11 '11 at 18:09

3 Answers3

1

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.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • Why would you `need` this directive? Correct UTF8 .cfm templates work perfectly with any non-ASCII chars, without any additional directives for ACF9 and Railo 3. Problem is in template/editor. – Sergey Galashyn Oct 06 '11 at 13:05
  • I've never had a problem with encoding before when using Dreamweaver, so I am with Sergii in that the issue must be with the template/editor. – eb_Dev Oct 06 '11 at 13:20
0
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)?

Sergey Galashyn
  • 6,946
  • 2
  • 19
  • 39
  • Yes, there is per file encoding in Aptana which is accessed the same was as in Eclipse, this shows that the .cfm file is UTF-8 also. – eb_Dev Oct 06 '11 at 13:18
-1

Try putting

<cfprocessingdirective pageencoding="utf-8" />

near the top of your Application.cfc

mz_01
  • 495
  • 3
  • 13
  • Here you find more informations: http://mysecretbase.com/ColdFusion_and_Unicode.cfm – da_didi Oct 06 '11 at 10:39
  • -1 sorry. CFPROCESSINGDIRECTIVE is a compiler directive, not a runtime one, so if one is to use it, it needs to go into every file that needs it. – Adam Cameron Oct 06 '11 at 11:22
  • It was just a SUGGESTION to TRY it, not a promise that it will let rainbows shoot out of his nose. – mz_01 Oct 07 '11 at 12:47