tracker issue : CF-4204028

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] Bug for: FileWrite() cannot change FileObject's charset

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

Reporter/Name(from Bugbase): Aaron N. / ()

Created: 02/17/2019

Components: File Management

Versions: 2018

Failure Type: Non Functioning

Found In Build/Fixed In Build: 2018.0.0.310739 /

Priority/Frequency: Normal / Some users will encounter

Locale/System: / Windows 10 64 bit

Vote Count: 0

Issue: FileWrite() cannot change FileObject's charset

This works:
----
{code:java}
<cfprocessingdirective pageencoding="utf8"><!--- B/c CF-3712167 --->
<cfscript>
  //cfprocessingdirective(pageencoding="utf8");//b/c auto-detection of page encoding randomly fails
  fileWrite(expandPath("./myfile1.txt"), "a", "us-ascii");
  fileWrite(expandPath("./myfile1.txt"), "€", "utf-8");//myfile1.txt becomes UTF8 (good)
</cfscript>
{code}

----

This fails:
----
{code:java}
<cfprocessingdirective pageencoding="utf8"><!--- B/c CF-3712167 --->
<cfscript>
  //cfprocessingdirective(pageencoding="utf8");//b/c auto-detection of page encoding randomly fails
  fileWrite(expandPath("./myfile2.txt"), "a", "us-ascii");
  myFileObject = fileOpen(expandPath("./myfile2.txt"), "write", "us-ascii");
  fileWrite(myFileObject, "€", "utf-8");//throws "Complex object types cannot be converted to simple values."
  fileClose(myFileObject);
</cfscript>
{code}

----

Suggestion: Allow `charset` parameter, when FileWrite() writes to myFileObject.

Attachments:

Comments:

Hi Aaron, Can you please try below code and let us know : {code:java} <cfprocessingdirective pageencoding="utf8"> <cfscript> fileWrite(expandPath("./myfile2.txt"), "a", "us-ascii"); myFileObject = fileOpen(expandPath("./myfile2.txt"), "write", "us-ascii"); fileWrite(myFileObject.path, "€", "utf-8"); fileClose(myFileObject); </cfscript>{code}   Thanks, Mukesh
Comment by Mukesh K.
30473 | March 12, 2019 11:55:05 AM GMT
Hi Aaron, Did you get the chance to look into previous comment ?   -Mukesh
Comment by Mukesh K.
30617 | April 10, 2019 06:32:51 AM GMT
Hi Mukesh, Yes, exactly, Filewrite() supports charset parameter with the filepath parameter. Your Filewrite() is basically the same as my "This works" example's Filewrite(). My point is that Filewrite() doesn't support the charset parameter with the fileobject parameter. If I FileOpen() a us-ascii file, I should be able to later Filewrite() the fileobject as utf-8. Basically, we're forced to use a file path in Filewrite(), in order to change the charset. I don't see what purpose that limitation serves..? Thanks!, -Aaron
Comment by Aaron N.
30618 | April 10, 2019 07:18:04 AM GMT